wpf - Finding specific pixel colors of a BitmapImage -
I have a WPF bitmap image, which I have loaded from .JPG file, as follows:
This.m_image1.Source = New bitmap image (new URI (route);
I would like to ask what is on color specific points. For example, what is RGB value on pixels (65,32)?
How can I go about this? I was taking this approach:
ImageSource ims = m_image1.Source; Bitmap image bitmap image = (bitmap image) IMS; Int height = bitmapImage.PixelHeight; Int width = bitmapImage.PixelWidth; Int nStride = (bitmapImage.PixelWidth * bitmapImage.Format.BitsPerPixel + 7) / 8; Byte [] pixelbatteryre = new byte [bitmap image. Pixelight * ns tride]; Bitmap image Copy pixel (pixelbieter, ns tride, 0);
However, I will admit that there is a monkey - see, monkeys go with this code. Anyway, is there a direct way to process this array of bytes to convert to RGB values?
Interpretation The source of the resulting byte array depends on the pixel format of the bitmap, but the 32 bit, the ARGb image In the simplest case, each pixel will be included in four bytes in the byte array. The first pixel will be interpreted in this way:
alpha = pixel bitere [0]; Red = pixelbetaurere [1]; Green = pixelbite array [2]; Blue = pixelbetaurere [3];
To process each pixel in the image, you probably want to increase the index variable by number of bytes in each pixel, create a nested loop to run on rows and columns.
Some bitmap types add one pixel by one byte For example, a monochrome image packs eight pixels in each byte if you have 24/32 bit per pixel (simple ones) If there is a need to deal, I would recommend finding a good book that covers the underlying binary structure of bitmaps.
Comments
Post a Comment