473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How do you save a prefuse visualization graph as jpeg image?

i want to save my prefuse visualization graph as jpeg image,plz help me with java code,how will i do it.
Jan 7 '08 #1
3 3576
BigDaddyLH
1,216 Expert 1GB
i want to save my prefuse visualization graph as jpeg image,plz help me with java code,how will i do it.
Take a look at the javax.imageio packages. It can be as simple as one line of code, if you have a BufferedImage:

Expand|Select|Wrap|Line Numbers
  1. boolean success = ImageIO.write(bufferedImage, "jpeg", file);
Jan 7 '08 #2
Take a look at the javax.imageio packages. It can be as simple as one line of code, if you have a BufferedImage:

Expand|Select|Wrap|Line Numbers
  1. boolean success = ImageIO.write(bufferedImage, "jpeg", file);

Hi Frnd,

m using prefuse visulation,it's have one display class and this class have one saveImage(outPutStream, String jpg,double size);. now graph is converting ia jpg image properly.now my problem is tht,If graph is to large if it going out of screen thn ,i m getting jpg image on screen disply graph,m not getting the image of tht graph which going out of screen. this is my code


d = new Display(visualization);
fileOutPutStream=new FileOutputStream("c:/sri/img.jpg");
d.saveImage(fileOutPutStream,"jpg",2.6);

plz if u can do some help me, tht plz do it
it's very important for me.
Jan 10 '08 #3
Hi Frnd's,

m using prefuse visulation,it's have one display class and this class have one saveImage(outPutStream, String jpg,double size);. now graph is converting ia jpg image properly.now my problem is tht,If graph is to large if it going out of screen thn ,i m getting jpg image on screen disply graph,m not getting the image of tht graph which going out of screen. this is my code



This is my code



import com.sun.corba.se.impl.orbutil.graph.Node;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.dnd.DragSource;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import javax.crypto.NullCipher;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.border.Border;

import prefuse.Constants;
import prefuse.Display;
import prefuse.Visualization;
import prefuse.action.Action;
import prefuse.action.ActionList;
import prefuse.action.RepaintAction;
import prefuse.action.assignment.ColorAction;
import prefuse.action.assignment.DataColorAction;
import prefuse.action.layout.graph.ForceDirectedLayout;
import prefuse.activity.Activity;
import prefuse.activity.ActivityAdapter;
import prefuse.activity.ActivityListener;
import prefuse.controls.DragControl;
import prefuse.controls.PanControl;
import prefuse.controls.ToolTipControl;
import prefuse.controls.ZoomControl;
import prefuse.controls.FocusControl;
import prefuse.controls.DragControl;
import prefuse.data.Graph;
import prefuse.data.Table;
import prefuse.data.Tuple;
import prefuse.data.io.DataIOException;
import prefuse.data.io.GraphMLReader;
import prefuse.data.io.GraphWriter;
import prefuse.data.tuple.TupleSet;
import prefuse.render.DefaultRendererFactory;
import prefuse.render.LabelRenderer;
import prefuse.render.ShapeRenderer;
import prefuse.util.ColorLib;
import prefuse.util.force.DragForce;
import prefuse.visual.NodeItem;
import prefuse.visual.VisualItem;
import javax.swing.*;
import java.awt.Container;
import java.io.FileInputStream;
import java.awt.Canvas;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowListener;
import java.awt.Image;
import java.util.Set;
class DrawGrahp extends JFrame{

private FileOutputStream fileOutPutStream=null;
private JButton button;
private JFrame frame;
private Visualization vis;
private LabelRenderer r;
private ActionList layout;
private ActionList color;
private Display d ;
private int a,b;
private Graph graph = null;
private JPanel jpanel;
public DrawGrahp(){
jpanel=new JPanel();


button=new JButton("Save");
Container con= getContentPane();
jpanel.setLayout(null);
button.setBounds(200,300,70,40);
con.setSize(500,600);
jpanel.setSize(1000,800);
final int l= jpanel.getHeight();
final int m=jpanel.getWidth();
Canvas canvas=new Canvas();

jpanel.add(button);

con.setVisible(true);
jpanel.setDoubleBuffered(true);
jpanel.setPreferredSize(new Dimension(500,600));
Point location=new Point();


System.out.println("Panel Size"+ jpanel.getSize());
System.out.println("panel height----------"+jpanel.getHeight()+"Panel width-------------"+jpanel.getWidth());
con.add(jpanel,BorderLayout.NORTH);


try {
graph = new GraphMLReader().readGraph("\\JavaApplicationSwing\ \graph.xml");
} catch (DataIOException e ) {
e.printStackTrace();
System.err.println("Error loading graph. Exiting...");
System.exit(1);
}




// nodes and edges are accessible as "graph.nodes" and "graph.edges"
vis = new Visualization();
vis.add("graph", graph);

vis.setInteractive("graph.edges", null, false);

// -- 3. the renderers and renderer factory ---------------------------


r = new LabelRenderer("name");
r.setRoundedCorner(8, 8); // round the corners
ShapeRenderer sh=new ShapeRenderer();
sh.star(2,3,4);
sh.setBaseSize(4);

// return our name label renderer as the default for all non-EdgeItems
// includes straight line edges for EdgeItems by default
vis.setRendererFactory(new DefaultRendererFactory(r));
d = new Display(vis);

// -- 4. the processing actions ---------------------------------------



int[] palette = new int[] {
ColorLib.rgb(255,180,180), ColorLib.rgb(190,190,255)

};

// map nominal data values to colors using our provided palette
DataColorAction fill = new DataColorAction("graph.nodes", "gender",
Constants.NOMINAL, VisualItem.FILLCOLOR, palette);


ColorAction text = new ColorAction("graph.nodes",
VisualItem.TEXTCOLOR, ColorLib.gray(0));

if(text.equals("sriniwas"))
{
new ColorAction("graph.nodes",VisualItem.TEXTCOLOR, ColorLib.green(240));
}
ColorAction edges = new ColorAction("graph.edges",
VisualItem.STROKECOLOR, ColorLib.gray(200));


color = new ActionList();
color.add(fill);

color.add(text);
color.add(edges);
int aa;
for(int i=0;i<color.size();i++){


System.out.println("sdhfshdfhsf" +i);
}

layout = new ActionList(Activity.INFINITY);
layout.add(new ForceDirectedLayout("graph"));
layout.add(new RepaintAction());





vis.putAction("color", color);
vis.putAction("layout", layout);


// -- 5. the display and interactive controls -------------------------
d = new Display(vis);






// d.setSize(1000, 600); // set display size


d.addControlListener(new DragControl());
d.addControlListener(new PanControl());
d.addControlListener(new ZoomControl());
d.addControlListener(new FrameFocusControl());
// d.addControlListener(new ToolTipControl(){


//d.addControlListener(new DragSource());


// -- 6. launch the visualization -------------------------------------

jpanel.add(d);
vis.run("color");
vis.run("layout");




button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(e.getSource()==button){
try{




jpanel.setSize(new Dimension(l*10,m*10));
System.out.println("Panel Hieght"+jpanel.getHeight());
System.out.println("Panel width"+jpanel.getWidth());
Image img =d.getOffscreenBuffer();
img.getSource();
System.out.println("A fter increase Panel Size"+ jpanel.getSize());
fileOutPutStream=new FileOutputStream("c:/sri/img.jpg");
d.saveImage(fileOutPutStream,"jpg",2.6);
fileOutPutStream.flush();
fileOutPutStream.close();

System.out.println("------------------"+jpanel.getHeight());
}catch(IOException ex){ex.printStackTrace();}

}
}
});

}



}


public class DrawGrahpDemo{
public static void main(String Arg[]){

DrawGrahp drawGraph=new DrawGrahp();

drawGraph.setVisible(true);
drawGraph.setSize(500,600);
drawGraph.setDefaultCloseOperation(JFrame.EXIT_ON_ CLOSE);

}
}


it's very importtant for me, plz help me.
Jan 10 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Matt Brelje | last post by:
I have an .aspx page from which users can upload an image. After a file is uploaded, I also save a 60x60 pixel thumbnail of that image. Works great. What I can't seem to do is save a CROPPED...
1
by: Sam Jost | last post by:
Bitmap.Save() does crash very often on Saving jpg's. It seems to dislike pictures on a random basis, but when it dislikes a picture there is no way around it. Take for example the picture...
12
by: yaya via DotNetMonster.com | last post by:
Hi, I have a picture box with circles and rectangles, and I wana save all the images into a jpg file, i tried pictureBox1.Image.Save(@"c:\1.jpg"); but I got and error...
2
by: Barry | last post by:
Hi Does anyone know why i am getting the following error message (line 64) , if i change to objBitmap.Save(Response.OutputStream, ImageFormat.Jpeg) i do not get this error Exception...
1
by: Ryan Moore | last post by:
I'm trying to make a page that, when opened, displays a file save dialog, then closes itself (essentially just leaving the file save dialog). Is this possible? I've tried this: ...
1
by: Ben Becker | last post by:
Why when I open an image in VB.NET, display it in an image box, then call the image.save property to save it to a file as a different format (e.g. tiff image with save to jpeg) does it become 10...
2
by: sriniwas | last post by:
Hi Frnd's, m using prefuse visulation,it's have one display class and this class have one saveImage(outPutStream, String jpg,double size);. now graph is converting ia jpg image properly.now my...
0
by: tavares | last post by:
(Our apologies for cross-posting. We appreciate if you kindly distribute this information by your co- workers and colleagues.) ...
3
by: neovantage | last post by:
Hey all, i have created image by mixing logo and the original image. It create image and show in the same window. I have done 3 steps for this. First i upload an image to my server by using...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.