Exemple #1
0
 private void mainForm_LoadClicked(object sender, EventArgs e)
 {
     if (openDialog.ShowDialog() == DialogResult.OK)
     {
         Bitmap bitmap = Bitmap.FromFile(openDialog.FileName) as Bitmap;
         if (bitmap.Width == PATTERN_SIZE && bitmap.Height == PATTERN_SIZE)
         {
             UnsafeBitmap fastBitmap = new UnsafeBitmap(bitmap);
             Pattern pattern = new Pattern(PATTERN_SIZE, PATTERN_SIZE);
             fastBitmap.LockBitmap();
             for (int j = 0; j < PATTERN_SIZE; ++j)
             {
                 for (int i = 0; i < PATTERN_SIZE; ++i)
                 {
                     PixelData colour = fastBitmap.GetPixel(i, j);
                     pattern[i, j] = colour.GetBrightness() > 0.5f ? PointColour.White : PointColour.Black;
                 }
             }
             fastBitmap.UnlockBitmap();
             patternInputPresenter.LoadPattern(pattern);
         }
     }
 }
Exemple #2
0
 private void AddNewCluster(Pattern pattern)
 {
     UnsafeBitmap bitmap = new UnsafeBitmap(pattern.Size.Width, pattern.Size.Height);
     PixelData black = new PixelData() { red = 0, green = 0, blue = 0 };
     PixelData white = new PixelData() { red = 255, green = 255, blue = 255 };
     bitmap.LockBitmap();
     for (int j = 0; j < pattern.Size.Height; ++j)
     {
         for (int i = 0; i < pattern.Size.Width; ++i)
         {
             bitmap.SetPixel(i, j, pattern[i, j] == PointColour.Black ? black : white);
         }
     }
     bitmap.UnlockBitmap();
     PictureBox newCluster = new PictureBox();
     newCluster.Image = bitmap.Bitmap;
     newCluster.Refresh();
     pClusters.Controls.Add(newCluster);
     pbWinner.Image = bitmap.Bitmap;
     pbWinner.Refresh();
 }