Today I downloaded the new Beta2 of 1.4, primarily because of the new imageio package and the promise that one could easily create jpgs from scratch. I have coded a simple program that draws a box on a Graphics2D, displays the image, and then writes the image to a .jpg. The program seems to work just fine except for one problem: the image is completely black. It must have something to do with the default background, but I can't figure out where/how to change it. setBackground on the Graphics2D has no affect. The image (all black box) is displayed properly on screen and the jpg (still all black box) is written to the local PC correctly. If I can just get over this background issue I'll be in business... Here is the code:
and this is the ApplicationFrame class that goes with it in case you want to try it out...
If anyone has any ideas it would be most appreciated... Ciao, Joel
[This message has been edited by Joel Cochran (edited October 26, 2001).]
Wait a minute, I'm trying to think of something clever to say...<p>Joel
Joined: Mar 23, 2001
Just in case anyone is curious, I was finally able to get over this hurdle yseterday. My best guess is that the background is the default background of the environment that started the program. In this case, that was a DOS prompt so the background was black. I changed the color of the lines to white and they shoed up just fine, so I went back to the drawing board... literally! Setting the background only works for the next Component, so I added some code after the createGraphics() method that essentially "painted" the entire image area white like so: g2.setColor( Color.white ); g2.fillRect( 0 , 0 , 300 , 300 ); Drawing on the image after that showed up correctly and my .jpg was properly created.
subject: SDK1.4, new IO ops, and creating JPGs...oh my!