mari Mir
mari Mir

Reputation: 39

bitmap.save is not saving exact pixel color in c#

I've changed all pixels color in one bitmap file with "bitmap.SetPixel" .when I save the bitmap on PC , the saved file has different colors for each pixel when I open it in photoshop .. !! the saved colors are close but not the same.. please help me.

set pixel color:

Bitmap.SetPixel(x, y, MyColor);

save bitmap :

Bitmap.Save(MyPath, PicImage.RawFormat );

Upvotes: 2

Views: 643

Answers (1)

TaW
TaW

Reputation: 54433

Note that Image.RawFormat is basically a shorthand for 'use the original image format!'

So, if your image source is a lossy compressed format like jpeg you are saving , i.e. re-encoding it in the same compressed format, but, most likely using a different compressor codec and/or different quality etc parameters.

So you can expect some slight color shifts.

Even with the very same codec etc a jpeg would have to create a different version of the compression tables just for the one pixel you are changing..

Make sure the original image uses a lossless compression, like png or some tif formats to avoid this effect.

To be sure you may want to specify the format explicitly.

Upvotes: 2

Related Questions