Hello!
Open bmp file.

image = new Bitmap(Image.FromFile(imagePath)); ....... //Затем изменяю цвет некоторых пикселей с помощью image.SetPixel(i,j,color); ........ image.Save(ImagePath, System.Drawing.Imaging.ImageFormat.Bmp);//Затем сохраняю: 

No more changes are made. Why does the output file size not match the input file? Height / width has not changed. Only the color changed. How to save the modified image in its original size?

  • would you save better in png;) - semenvx27
  • We need exactly BMP))) - Freest

1 answer 1

The size changes because the image coding parameters change (color depth, quality or mn). Here is a link to the image encoding options when saving

For the size to be the same, you need to use this overload of the Save method and in the parameters specify EncoderParameters the same as in the original image.

  • Thank! And how do I pull EncoderParameters from the source image? - Freest
  • I have no idea, to be honest. - Ivan Navoznov
  • there type structure is recorded at the beginning of the file. It is in the form of C ++, but this can be converted to C #. read file header via FileStream - semenvx27
  • Surely in c # there is already something similar. We just need to find. :) - Ivan Navoznov