I writing a code to color my bitmap image pixels for
int[,] unClusteredImage = new int[367,158];
Bitmap clusteredImage = new Bitmap(367, 158);
for (int row = 0; row < unClusteredImage.GetLength(0); row++)
for (int col = 0; col < unClusteredImage.GetLength(1); col++)
if (unClusteredImage[row, col] == 0)
clusteredImage.SetPixel(row, col, Color.Red);
else if (unClusteredImage[row, col] == 1)
clusteredImage.SetPixel(row, col, Color.Blue);
else if (unClusteredImage[row, col] == 2)
clusteredImage.SetPixel(row, col, Color.Green);
else if (unClusteredImage[row, col] == 3)
clusteredImage.SetPixel(row, col, Color.Yellow);
else if (unClusteredImage[row, col] == 4)
clusteredImage.SetPixel(row, col, Color.Black);
else if (unClusteredImage[row, col] == 5)
clusteredImage.SetPixel(row, col, Color.Orange);
else if (unClusteredImage[row, col] == 6)
clusteredImage.SetPixel(row, col, Color.Lime);
else if (unClusteredImage[row, col] == 7)
clusteredImage.SetPixel(row, col, Color.Purple);
clusteredImage.Save("test.jpeg");
The problem is that when i save the bitmap using the bitmap.save method I lose some pixels when I open it in paint I noticed that some pixels are not there in the bottom of my image
You are saving the image as JPEG.
JPG format is a lossy compressed file format. This makes it useful for storing photographs at a smaller size than a BMP.
PNG format is a lossless compression file format, which makes it a common choice for use in applications.
I suggest you try to save it in PNG Format, and check the result. And if you don't care about the size you can always save it as Bitmap.
clusteredImage.save("test.png", ImageFormat.Png);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.