wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Saving a drawed image to a file reverses its colors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Saving a drawed image to a file reverses its colors" Watch "Saving a drawed image to a file reverses its colors" New topic
Author

Saving a drawed image to a file reverses its colors

Fernando Piovani
Greenhorn

Joined: Feb 09, 2011
Posts: 10
Well, i'am using Graphics2D to draw a image, and iam saving that image to a png file. What it happens is that the background goes black as the strokes go white. This is the code:



buffer = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB); Ive tryed changing the color format to other types, but didnt work as i expected.

My question is, where/how do i define the color for background and stroke, since g2.setColor, g2.setBackground didnt work as well.

ps: The file is drawed to a panel.

Thankz for your attention.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4637
    
    5

First off, and probably unrelated to the rpoblem you seek help with, a painting method override is no place to be performing disk I/O or constructing BufferedImages or most any other object, with the possible exception of geopmetry primitives (and that too is best avoided). Any painting method must be lean and return fast.

If you need frequent or periodic updates, use a Swing Timer and cal repaint() when done. Your painting method override will then have just one line to paint the already loaded image (and a call to the super implementation if the entire component area isn't covered by the image -- not the case here).

I don't see anywhere that you fill the background of your new BufferedImage, nor where you set the color of its Graphics reference, so I would fully expect
that the background goes black as the strokes go white.


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Saving a drawed image to a file reverses its colors