The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

How to generate JPEG Images?

Posted by Sudhakar on October 16, 2000 at 12:45 PM

Hi folks,
I want to generate a PIE-chart using data available in the database (in PJEG format). Could anyone guide me on the same? I have been able to create JPEG images but do not know if there are some utilities or some way of generating them. The following is the code I used for JPEG generation but it seems to be a real crude method if i am looking at generating pie-charts.


import com.sun.image.codec.jpeg.*;
import java.awt.image.*;
import java.awt.*;
import java.io.*;

public class Picture
{
static Graphics pie;
// static BufferedImage Bi;
// static Graphics2D Gra;

public static void main(String args[])
{
BufferedImage Bi=new BufferedImage(100,100,1);
// pie.drawOval(100,100,100,100);

pie=Bi.getGraphics();
Color col=new Color(210,210,210);
pie.setColor(col);
pie.drawOval(0,0,100,100);
pie.drawLine(0,100,100,0);
// pie.setColor(col);
// Picture pic =new Picture();
JPEGImageEncoder ImgEnc;

try
{
ImgEnc = JPEGCodec.createJPEGEncoder(new FileOutputStream("Abc1.jpg"));
ImgEnc.encode(Bi);
ImgEnc.getOutputStream().close();
}
catch(Exception e)
{
e.printStackTrace();
}
}

}
Let me know if there is an alternative for the same. Thank you,
Regards,
Sudhakar



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us