Good day to everyone. I need to read images pixel data using bitmap. Than make something with this data and write back to image. Doing this using GetPixels & SetPixels functions
string ImageFilePath = "image.jpg";
Bitmap image = Bitmap(ImageFilePath);
.....
for (int i = 0; i < image.Height; i++)
{
for (int j = 0; j < image.Width; j++)
{
Color pixelColor = image.GetPixel(j, i);
RedColor [i, j] = pixelColor.R;
GreenColor[i, j] = pixelColor.G;
BlueColor [i, j] = pixelColor.B;
}
}
.......
for (int y = 0; y < image.Height; y++)
{
for (int x = 0; x < image.Width; x++)
{
...............
image.SetPixel(x, y, Color.FromArgb(red, green, blue));
}
}
With 24bbp images it's work fine. But with Format8bppIndexed have some troubles, using method below (GetPixels) obtain wrong pixels values. Not to mention the record back to the file after some counting.
Can some one give code example how can I read\write 8bpp images using bitmap correctly (by obtaining pixel data)? Searching some examples before, but my "
crooked hands" didn`t allow to use what I have found.