Solved

Save all canvas area, not only the visible area

Posted on 2009-05-07
8
933 Views
Last Modified: 2013-12-29
Hello, Experts!
My question is: how can I save the canvas area, not only the visible area. See attached code. Thank you!!!
public void savePNG(String filename,Transport v,int _minX, int _minY,int _maxX, int _maxY) throws IOException {
	WhiteboardContext wb=this;
	//now save all shapes...
	BufferedImage img = new BufferedImage(_maxX-_minX,_maxY-_minY, BufferedImage.TYPE_INT_RGB);
	Graphics g=img.createGraphics();
    //wb.setXOffset(-_minX);
	//wb.setYOffset(-_minY);
    Graphics2D g2d = (Graphics2D)g;
    g2d.setBackground(Color.WHITE);
    g.fillRect(0,0,_maxX-_minX,_maxY-_minY);
 
	for(Enumeration e=v.getAllShapes().elements();
		e.hasMoreElements(); ) {
	    Tool.Shape s=(Tool.Shape)(e.nextElement());
	    s.updateState(wb);
	}
	for(Enumeration e=v.getAllShapes().elements();
		e.hasMoreElements(); )
    {
	    Tool.Shape s=(Tool.Shape)(e.nextElement());
	    s.paint(wb, g2d);
	}
	ImageIO.write(img, "png", new File(filename));
    System.out.println("saved...");
    }

Open in new window

0
Comment
Question by:profesoralex2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 24330718
afaicr you can't. You can only save visible areas
0
 
LVL 92

Expert Comment

by:objects
ID: 24331874
shouldn't be a problem (assuming they are all getting passed to you). What exactly is happening?

0
 

Author Comment

by:profesoralex2
ID: 24331999
Ok, when I try to save the picture NOT from the upper left corner, I get the picture 1.
When I trye to save the picture FROM the upper left corner, I get the picture 2.
So the problem is that I can change the picture's size to save it, but only when I make visible the upper left corner (tha't, when I move the picture to the left upper corner). In other case the picture is not saved entirely. I gues i have problems with the coords.
Thanks!!!

Alex
080520090208019f9f197d-f4d7-4ba8.png
080520090208017d97916e-b354-406d.png
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 92

Expert Comment

by:objects
ID: 24332852
yes, you need to define the coords to include the complete image
You can scale it if you you want to control the resulting image size independent of the source

0
 

Author Comment

by:profesoralex2
ID: 24333309
Could you provide me a code to do it? Thank you!
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 24334176
What happens when you change

>>_maxX-_minX

for _maxX and

>>_maxY-_minY

for _maxY throughout?
0
 

Author Comment

by:profesoralex2
ID: 24369513
"What happens when you change

>>_maxX-_minX

for _maxX and

>>_maxY-_minY

for _maxY throughout?"

Doesn't work....
0
 
LVL 92

Expert Comment

by:objects
ID: 24370515
what is you you want to achieve?

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What's wrong with this code? 4 36
mysql jsp example issue 32 75
add projects t working set in maven 2 44
Eclipse with various Java releases 7 53
The purpose of this article is to demonstrate how we can use conditional statements using Python.
In this post we will learn different types of Android Layout and some basics of an Android App.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question