Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+18 votes

Does anyone know why the method canvas.saveImageWithoutErrors() saves .jpg images with incorrect coloring? I can't pinpoint a solution as to why this happens. In the canvas DrawingPanel, the image's colors are correct, but when they are saved in .jpg format, the colors alter. If they are saved in .png format, however, the colors are fine. Is there a reason why this happens?

https://imgur.com/SRW8xQY -- owl in PNG
https://imgur.com/Gtdsg2X -- owl in JPG

asked in CSC211_Winter2018 by (1 point)

2 Answers

+9 votes
 
Best answer

Honestly, I'm not entirely sure myself. There's some kind of bug in the Java method that DrawingPanel is calling to save JPEG images, regarding whether there are three channels (R,G,B) or four channels (R,G,B, A) where A is for alpha/transparency. Other people have run into this problem too. The DrawingPanel reads JPEG files just fine, but doesn't save/write them correctly.

My recommended (work-around) solution: just output all your artwork as .PNG files (like the assignment specifies.)

answered by (508 points)
selected by
+8 votes

Well I think, in graphics design the jpg format usually have different color code from the png format like RGB and CMYK. But I think the different color in your picture because of your code

answered by (1 point)
...