Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Export as .png file resolution (Read 2798 times)
Patrick Guerin
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Dec 11th, 2014
Export as .png file resolution
Dec 16th, 2014 at 5:01pm
Print Post  
Does anybody know how to export JDiagram Graph in PNG in high resolution ?  Actually, I use the function java.awt.image.BufferedImage image = diagram.createImage(); to export the image of the graph.  But the output resolution seem to be link with the width and height of the document Graph.  I was thinking the function (setImageDpiX(dpi)) would help, but it's not the case.  Thanks for help.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Export as .png file resolution
Reply #1 - Dec 16th, 2014 at 5:59pm
Print Post  
By resolution do you mean image size in pixels (width x height ), or logical pixel density? For density check the solution here:
http://stackoverflow.com/questions/321736/how-to-set-dpi-information-in-an-image

You can export more pixels per diagram unit using the following code, and combine it with PNG serialization code from topic above:

Code
Select All
private void testPngExport()
{
	double dpiScale = 4;
	double unitScale = Utilities.convert(
		1, diagram.getMeasureUnit(), GraphicsUnit.Point);
	double scale = unitScale * dpiScale;

	// create bitmap image
	BufferedImage img = new BufferedImage(
		(int)(diagram.getBounds().getWidth() * scale),
		(int)(diagram.getBounds().getHeight() * scale),
		BufferedImage.TYPE_INT_ARGB);

	// draw the diagram
	Graphics2D graphics = img.createGraphics();
	graphics.scale(scale, scale);
	diagram.draw(
		graphics,
		new RenderOptions(),
		diagram.getBounds());

	File file = new File("test.png");
	try
	{
		ImageIO.write(img, "png", file);
	}
	catch (IOException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
} 

  
Back to top
 
IP Logged
 
Patrick Guerin
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 21
Joined: Dec 11th, 2014
Re: Export as .png file resolution
Reply #2 - Dec 16th, 2014 at 8:02pm
Print Post  
Wow !  It works perfectly...  Thank you very much...   Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint