0

I've parsed an image with the following code

Bitmap img = (Bitmap)Bitmap.FromFile("file.jpg");

And after saved so

img.Save("file2.jpg");

I did not modify anything, but looking on diff of the both images, I see that the new one is different. How I can fix that? I want to keep the colors

Jim
  • 2,974
  • 2
  • 19
  • 29
  • Do you use some non standard library? Where is `Canvas.FromFile()`? – romanoza Dec 13 '16 at 22:17
  • No, standard. `System.Drawing` – Ivan Ivanov Dec 13 '16 at 22:19
  • What are you targetting: Winforms, WPF, ASP..? __Always__ tag your question correctly! – TaW Dec 13 '16 at 22:26
  • @TaW, I write codes on C# very rare, I did not know there is any difference, sorry – Ivan Ivanov Dec 13 '16 at 22:28
  • 1
    Can't find anything like `System.Drawing.Canvas` – romanoza Dec 13 '16 at 22:29
  • I missed with `Bitmap`, edited – Ivan Ivanov Dec 13 '16 at 22:32
  • The colors should not really change but saving without specifying the quality may well creat quite some differences! Look up the overload with jpeg encoder! – TaW Dec 13 '16 at 22:34
  • You did not use the Save() overload that specifies the ImageFormat. So you actually got a PNG file. Stored in a filename with the .jpg extension. Yeah, like, don't do that. – Hans Passant Dec 13 '16 at 22:59
  • @HansPassant, I saved as jpeg now, but still a number of pixels is different. Tried these advices http://stackoverflow.com/questions/21218017/how-to-save-a-bitmap-image-as-jpeg and http://stackoverflow.com/questions/1669850/high-quality-jpeg-compression-with-c-sharp – Ivan Ivanov Dec 15 '16 at 19:17

0 Answers0