PDA

Click to See Complete Forum and Search --> : Component to a JPEG and i enclose a piccy!


Andy_Hollywood
Aug 21st, 2003, 10:15 AM
Hello

I have a JDesktopPane with some internal windows, and an extra
JPanel in one of the layers!

havea look att he picture attachment and you'll undertsand what i mean.

I'd like to output what i have inthe desktop area to a JPEG, now i can output to a JPeg fine with this code:


try{
// component.setBackground(Color.WHITE);
Dimension d = component.getPreferredSize();
BufferedImage bimage = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);

component.paintImmediately(new Rectangle(d.width, d.height));
component.paintAll(bimage.createGraphics());
//component.paint(bimage.createGraphics());


if(!path.endsWith(".jpg"))
path += extension;
OutputStream out = new FileOutputStream(path);
ImageIO.write(bimage, "jpeg", out);
out.close();
}catch (Exception e){
System.out.println(e);
}



Now the problem i am having is when i move an internal frame so half of it is hidden by the edge of the sccreen and i print i end upw oith the image that is on the left hand side, i.e. the big black line, now i change the preffered size of the desktop to the MAX X,Y locatiosna dn widths of any internal frame, so it will alway return the full area.

Now the printing works fine, if you look at the one onthe right, its drawn my diagrma ok, i was wondering if i am missing somehting, or if there is another way to force the dekstop pane to repaint everyhting in it?!

does that make sense?! hope so

if not let me know and i'll have another stab.

Cheers

Andy

Dillinger4
Aug 21st, 2003, 10:32 AM
validate() is usually invoked which results in the updating of the container and it's parents. Im not sure if this method can be called explicitly but it's worth a try.

Andy_Hollywood
Aug 21st, 2003, 10:38 AM
Hrm, i called validate, but it pretty much gave me the same results.

Do you reckon it could because its a JDesktopPane, that is not scrollable, so it dosen't know its got anyhting outside of the view port.... know what i mean?!


is there an easy way to get a JDesktopPAne to scroll?!? i already know that you can't simply add it to a JScrollPane.. no that would be to easy!

Andy_Hollywood
Aug 22nd, 2003, 06:11 AM
Hello again

i ended up implementing a scrolling desktop, mainly because i had to anyway and also to see if it woul dimprove my painting and writing to a JPEG.

I have changed my JPEG coe to :


try{
component.setBackground(Color.WHITE);
Dimension d = component.getSize();
BufferedImage bimage = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);
//component.validate();
component.paintImmediately(new Rectangle(d.width, d.height));
component.repaint();
component.paintComponents(bimage.createGraphics());


if(!path.endsWith(".jpg"))
path += extension;
OutputStream out = new FileOutputStream(path);
ImageIO.write(bimage, "jpeg", out);
out.close();
}catch (Exception e){
System.out.println(e);
}


And as a result it actually gives me a picture like the one i have attached.

Tome it looks like it painting all sorts, as if i haven't flushed a buffer somewhere!?!/
any ideas?