Results 1 to 4 of 4

Thread: Component to a JPEG and i enclose a piccy!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222

    Component to a JPEG and i enclose a piccy!

    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:

    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
    Attached Images Attached Images  

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222

    hrm

    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!

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222

    Scrolling Desktop and new Paint Issue

    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 :

    Code:
    	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?
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width