x0 = 0; y0 = 0; xmax = 0; ymax = 0; // GDI+ still lies to us - the return format is BGR, NOT RGB. BitmapData bmData = EditImage.LockBits(new Rectangle(0, 0, EditImage.Width, EditImage.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); int stride = bmData.Stride; System.IntPtr Scan0 = bmData.Scan0; unsafe { byte* p = (byte*)(void*)Scan0; int nOffset = stride - EditImage.Width * 3; for (int y = 0; y < EditImage.Height; ++y) { for (int x = 0; x < EditImage.Width; ++x) { if ((y == 0) && (x == 0)) { awalB = p[0]; awalG = p[1]; awalR = p[2]; } else { if ((awalB == p[0]) && (awalG == p[1]) && (awalR == p[2])) { } else if (x0 == 0) { x0 = x; } else { xmax = x; } } p += 3; } p += nOffset; } } unsafe { byte* p = (byte*)(void*)Scan0; int nOffset = stride - EditImage.Height * 3; for (int x = 0; x < EditImage.Width; ++x) { for (int y = 0; y < EditImage.Height; ++y) { if ((y == 0) && (x == 0)) { awalB = p[0]; awalG = p[1]; awalR = p[2]; } else { if ((awalB == p[0]) && (awalG == p[1]) && (awalR == p[2])) { } else if (y0 == 0) { y0 = y; } else { ymax = y; } } p += 3; } p += nOffset; } } EditImage.UnlockBits(bmData); x1 = xmax - x0; y1 = ymax - y0; _selection = new Rectangle(new Point(x0, y0), new Size()); _selection.Width = x1; _selection.Height = y1; // Create cropped image: Image img = pbox_hasil.Image.Crop(_selection); // Fit image to the picturebox: pbox_hasil.Image = img.Fit2PictureBox(pbox_hasil);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)