Hi i have a bmp
loaded to a BMP
object and im required to travel though the pixels as the above image from (1,1)
pixel to (100,100)
px . using getpixel()
method. I was using was ONE loop but it was not successful .
If im using the concept of multidimensional array what should be variable values ?
Bitmap (BMP) BMP is a standard format used by Windows to store device-independent and application-independent images. The number of bits per pixel (1, 4, 8, 15, 24, 32, or 64) for a given BMP file is specified in a file header. BMP files with 24 bits per pixel are common.
If you use a PC or Mac, start by opening the folder with the BMP file you want to use. Right-click on the file name and then hover over the Open With option. You can then choose from any number of applications to display your BMP file. These may include Adobe Photoshop, Windows Photos, Apple Photos, and more.
The final part of the BMP file is the image data. The data is stored row by row with padding on the end of each row. The padding ensures the image rows are multiples of four.
When you want to doing image processing on huge images GetPixel() method takes long time but I think my algorithm takes less time than other answers , for example you can test this code on 800 * 600 pixels image.
Bitmap bmp = new Bitmap("SomeImage"); // Lock the bitmap's bits. Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); // Get the address of the first line. IntPtr ptr = bmpData.Scan0; // Declare an array to hold the bytes of the bitmap. int bytes = bmpData.Stride * bmp.Height; byte[] rgbValues = new byte[bytes]; byte[] r = new byte[bytes / 3]; byte[] g = new byte[bytes / 3]; byte[] b = new byte[bytes / 3]; // Copy the RGB values into the array. Marshal.Copy(ptr, rgbValues, 0, bytes); int count = 0; int stride = bmpData.Stride; for (int column = 0; column < bmpData.Height; column++) { for (int row = 0; row < bmpData.Width; row++) { b[count] = (byte)(rgbValues[(column * stride) + (row * 3)]); g[count] = (byte)(rgbValues[(column * stride) + (row * 3) + 1]); r[count++] = (byte)(rgbValues[(column * stride) + (row * 3) + 2]); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With