Save Applet as a jpeg/gif image

I wrote a small applet to draw some lines.
it work fine.
What i want to know is how can i save this applet to a jpeg/gif file.
(Assume there is a Button in the Applet or Even in the HTML page; when click the button needs to save the applet as an image file)
is it possible??
import java.applet.*;
import java.awt.*;
public class Test extends Applet {
   int width, height;
   public void init() {
      width = getSize().width;
      height = getSize().height;
      setBackground( Color.black );
   public void paint( Graphics g ) {
      g.setColor( Color.green );
      for ( int i = 0; i < 10; ++i ) {
         g.drawLine( width, height, i * width / 10, 0 );
<applet code="Test" width="300" height="300">
</applet>
Message was edited by:
jugp

After finding out some facts i tried to do like this;
but still having some runtime exceptions....
need help from anybody!!!
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
public class Test extends Applet implements ActionListener{
   int width, height;
Image backbuffer;
   Button save;
   public void init() {
      save = new Button("save");
      add(save);
      save.addActionListener(this);
           width = getSize().width;
      height = getSize().height;
      setBackground( Color.black );
   public void paint( Graphics g ) {
      g.setColor( Color.green );
      for ( int i = 0; i < 10; ++i ) {
         g.drawLine( width, height, i * width / 10, 0 );
   public void actionPerformed(ActionEvent e) {
     String cmd = e.getActionCommand();  
     if (cmd.equals("save")){
             BufferedImage bufferedImage = new BufferedImage ( width, height,
                   BufferedImage.TYPE_INT_BGR  );
                    bufferedImage.createGraphics().drawImage( backbuffer, 0, 0, this);
               try {
                    ImageIO.write( bufferedImage, "jpg", new File ( "image.jpg" ) );
               } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
<applet code="Test" width="300" height="300">
</applet>
*/

Similar Messages

  • Need help to create report with jpeg/gif image

    Hello,
    I need help with creating a form with a special jpeg/gif seal. I never done this Java. Until now, I created all forms with ansi C++ with HP escape characters to draw lines, boxs, and text. This form will contain boxes which is populated with database information read from a text file.
    Since this form contains a special seal on the upper right, I don't think it can be done with old fashion ansi C++. How can I create a form with Java and create it as a simple exe to just print the form to a specified printer.
    Thanks,
    John

    Hi,
    I am creating a form with boxes (lines and text). What is special about this form is that it has an image jpeg or gif at the top right corner. Is is a state department seal. Up to this form, I had used ansi C++ and print out escape HP character to print out the lines, boxes, and text. I have no idea how to print out the image. I am new to JAVA and only 1 class in it. Is there sample code out there to create this type of form with the image? I need a starting point.
    Thanks,
    John

  • How i can insert or save ( PDF, EXCEL, WORD, JPEG ) in IMAGE ITEM.

    Dear All,
    plz advise how i can save PDF, EXCEL, WORD, JPEG files in IMAGE FILE.
    Thanks in advance
    ASIM.

    Start by creating an Item type of OLE container. Set the following properties:
    - OLE Tenant Types: Embedded
    - Database Item: Yes
    Make that item the last item in the block.
    Create a push button such as 'Insert Document' with similar code:
    DECLARE
      vcFile VARCHAR2(1024);
    BEGIN 
      vcFile := win_api_dialog.Open_File('Select Document File to Insert',NULL,'MS-Word files (*.doc)|*.doc|'||
         'PDF files (*.pdf)|*.pdf|Excel Files (*.xls)|*.xls|Outlook message files (*.msg)|*.msg|All files (*.*)|*.*|',
         TRUE,win_api.OFN_FLAG_DEFAULT,TRUE);
      go_block('<block name>');
      last_record;
      Create_Record;
      initialize_container('<oleitemname>',vcFile);
    EXCEPTION
      WHEN NO_DATA_FOUND Then
         Null;
    END;

  • JPEG/GIF image to BASE64

    Hi,
    I like to convert JPEG/GIF or any type of image into BASE64 format and Viceversa. Can somebody provide me the java code for doing this.
    Cheers,
    Siva Maranani.

    Rather than use an undocumented API, I would suggest a 3rd party library for Base64 encoding such as the one that I wrote:
    http://ostermiller.org/utils/Base64.html
    It even has several convenience methods for encoding files:
    static void      encode(File fIn)
    Encode this file in Base64.
    static void      encode(File fIn, boolean lineBreaks)
    Encode this file in Base64.
    static void      encode(File fIn, File fOut)
    Encode this file in Base64.
    static void      encode(File fIn, File fOut, boolean lineBreaks)
    Encode this file in Base64.

  • Loading JPEG/Gif images causes Out Of Memory Error

    Hello Java gurus, please shed some light on this.....
    I am not a java newbie, but I am a java newbie in the area of dealing with graphics. I am using JDK 1.4.2_01 on Win XP with 2.4ghz and 512 RAM. When I try to read in a (or a few) JPEG image into a JLabel using ImageIcon, I get an out of memory error everytime. This happens whether I am reading the image out of a jar file or out of a local directory. The JPEG's are 8.5" x 11", and range between 150kb to 900kb. I am trying to load approximately 10 images in a JTabbedPane using new JLabel(ImageIcon) on individual JPanels (one JPanel for each JPEG). Now I get the java.lang.outofmemory error whether I try to load 1 image or 10 images. Anyone got a clue as to what I am doing wrong? I actually do get one image loaded before the error gets thrown. So I do know that it is trying to load the right image. What is going on here? Is it an ImageIcon problem, or are there others who have run into this. It has brought this project to a grinding halt, and I had thought this would be the easier part!!!! Please help me out gurus! Thanks!

    What options/values are you suggesting that I set? Or do you mean something else? Thank you for any ideas that can help me solve this problem. I never had any issues dealing with using ImageIcon for toolbar button graphics (file sizes of 1-3kb), but now with dealing with full page graphics I have run into a brick wall with this out of memory error.

  • Image (jpeg, gif) display in AWT layout manager

    Goodmorning All,
    I am looking for some help, a hint on my AWT Layout challenge i have.
    Example GUI_1:
    =========================
    Window border..................[_][x]..
    =========================
    [label]....|display_area|....[button].
    [label]....|display_area|....[button].
    ...............|display_area|....[button].
    ...............|display_area|....[button].
    ...............|display_area|..................
    =========================
    ...........................................[QUIT].....
    =========================
    I want to
    - display a picture in the "display area" of the this GUI
    - put labels left of it with some text
    - put a couple of buttons right of it, through which i am able to manipulate the image
    Questions:
    *1. Is it (even) possible to display an (jpeg,gif) image in the "display area" while using a layout manager?*
    Surfing over the internet...so far i only have found applet-examples that use the full gui surface of the applet to display an image via the g.drawImage (imagename, x,y); without any gui elements (labels, buttons) beside it.
    *2. What kind of AWT gui element do i need at the location of the "display area"?*
    Is is possible to use a CANVAS or do i need somethen else? (e.g. glue an image on a button)
    *3. Is is possible to display an ANIMATION (series of sequences jpeg, gifs) in the display area?*
    I already found out how to locate and load the images (via mediatracker).
    Now i need to find a way to "paint" the loaded images in the GUI.
    *4. Is this even possible with AWT layout or do i need to switch to SWING layout?*
    I have not used Swing yet, cause i'm working my way up through the oldest gui technologie first.
    *5. Do know any usefull websites, online tutorials (on awt and displaying images) that can help me tackle my challenge?*
    Thank you very much for your hints, tips and tricks

    A link as Gary pointed out is the best way to see what the problem may be.
    Did you save the image to your working folder and have you defined a site pointing to this folder.
    Defining a site helps Dreamweaver track and organize the files used in this site.
    http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_14028
    If you can't see the image, this means that the path to the image is incorrect.
    Nadia
    Adobe Community Expert : Dreamweaver
    Unique CSS Templates | Tutorials | SEO Articles
    http://www.DreamweaverResources.com
    Web Design & Development
    http://www.perrelink.com.au
    http://twitter.com/nadiap

  • Saving a Gif image using JAI (Java Advanced Imaging)

    I'm trying to read in and save out a bunch of gif images in JAI. I'm reading them in, resizing them, and then saving them back out, all in gif format.
    For some reason some of my gif images work fine, and some don't throw any errors, but save as 0k size.
    When I do img.getColorModel().toString(); I get the following output for images that do work:
    IndexColorModel: #pixelBits = 8 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1bbf1ca transparency = 1 transIndex = -1 has alpha = false isAlphaPre = false
    And the following output for images that don't work:
    ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1bbf1ca transparency = 1 has alpha = false isAlphaPre = false
    If I try to save the images that don't work out as jpg's they work fine, but if I try to save them out as gif's, I get 0k files.
    Any insight on how to correct this problem?
    I assume it has something to do with the 24 numComponents in the non-working gifs, but I'm really not sure.
    Please help.
    Thanks.

    Can you post your image property?
    Try using this for image compression:
    int pixelSize = img.getColorModel().getPixelSize();
    if (1 == pixelSize) {
    tiffEncodeParam.setCompression(TIFFEncodeParam.COMPRESSION_GROUP3_2D);
    } else if (8 == pixelSize) {
    tiffEncodeParam.setCompression(TIFFEncodeParam.COMPRESSION_DEFLATE);
    } else if (24 == pixelSize) {
    tiffEncodeParam.setCompression(TIFFEncodeParam.COMPRESSION_JPEG_TTN2);
    Thanks,

  • How to save applet in image(gif/jpeg) format

    Hi there !
    how to save applet in image (gif/jpeg) format. i have just gone through JIMI package where serilization is there ,WHERE U CAN SORE in image format ...........can anybudy help me out.........if possible then pleeez provide me some example.
    Thanks in advan...........

    I think that is possible because i have seen some commercial applets that do that.
    -http://www.izhuk.com/painter/
    -http://www.lawrencegoetz.com/programs/signature/
    Thses two saves the image in the server since applets cant write in the host they are running. Maybe it would be possible whit JFS, i don't know.
    For now I am trying to store an image draw in the applet on my server.
    My idea now is copying the image to a buffer or something, open a connection to the server and receive the image with a perl CGI.
    There is an example with text:
    -http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html
    I want to do something similar but with an image.

  • How combine a jpeg image & animated gif image & save  it as GIF ?

    i have an jpeg image, & also aminated gif image, how do i place the animated gif image over (in the center of the image) a jpeg image & save it as gif file ??

    First thing you need to do is stop thinking in terms of file formats once the files are in photoshop they are all the same. The exception being vector vs raster. But in this instance the process is rteally the same so 6 on one hand a half a dozen on the other. Or as some would say Tomatoe, tomahtoe(mispelled on purpose).
    The jpeg I would assume is the background image and the gif image is the fore ground object. Open the jpeg, and then place the gif file. As long as the fore ground object has transparency, your job is pretty much done. If not, then it will be up to you to mask what you want to keep vs what you don't and apply that selection to the foregrounds layer as a mask.
    Google the net or skim the users manual for the keywords - mask, selections, quickmask, pen tool, paths. Each of these can in one way or another take care of your issue.
    It would be worth your time to also go through the numerous videos about photoshop and see how its done.
    Either go to adobe tv,
    Itunes podcasts
    or one of the following web sites:
    http://kelbytv.com/
    http://creativesuitepodcast.com/

  • Save  applet  as  images

    I create graphical report using jfree chart . it gives output in applet now i want to save applet as jpg image .
    is it possible ?
    i tried but i got image contain only black color.
    here is my code.
    package com.webaccess.wasurvey.action;
    import com.lowagie.text.Image;
    import java.awt.image.BufferedImage;
    import java.awt.image.ImageObserver;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.axis.CategoryAxis;
    import org.jfree.chart.axis.CategoryLabelPosition;
    import org.jfree.chart.axis.CategoryLabelPositions;
    import org.jfree.chart.axis.CategoryLabelWidthType;
    import org.jfree.chart.plot.CategoryPlot;
    import org.jfree.chart.plot.PlotOrientation;
    import org.jfree.data.category.CategoryDataset;
    import org.jfree.data.category.DefaultCategoryDataset;
    import org.jfree.text.TextBlockAnchor;
    import org.jfree.ui.ApplicationFrame;
    import org.jfree.ui.RectangleAnchor;
    import org.jfree.ui.RefineryUtilities;
    import org.jfree.ui.TextAnchor;
    import org.jfree.util.Log;
    import org.jfree.util.PrintStreamLogTarget;
    * A simple demonstration application showing how to create a horizontal 3D bar chart using data
    * from a {@link CategoryDataset}.
    public class BarChart3DDemo2 extends ApplicationFrame {
    // * JFREECHART DEVELOPER GUIDE *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available *
    // * to purchase from Object Refinery Limited: *
    // * Sales are used to provide funding for the JFreeChart project - please *
    // * support us so that we can continue developing free software. *
    * Creates a new demo.
    * @param title the frame title.
    public BarChart3DDemo2(final String title) {
    super(title);
    // create the chart...
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(23.0, "Series 1", "London");
    dataset.addValue(11.0, "Series 1", "New York");
    dataset.addValue(12.0, "Series 1", "Istanbul");
    dataset.addValue(13.0, "Series 1", "Cairo");
    dataset.addValue(13.0, "Series 2", "London");
    dataset.addValue(19.0, "Series 2", "New York");
    dataset.addValue(19.0, "Series 2", "Istanbul");
    dataset.addValue(19.0, "Series 2", "Cairo");
    dataset.addValue(7.0, "Series 3", "London");
    dataset.addValue(9.0, "Series 3", "New York");
    dataset.addValue(9.0, "Series 3", "Istanbul");
    dataset.addValue(9.0, "Series 3", "Cairo");
    final JFreeChart chart = createChart(dataset);
    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
    * Creates a chart.
    * @param dataset the dataset.
    * @return The chart.
    private JFreeChart createChart(final CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createBarChart3D(
    "3D Bar Chart Demo 2", // chart title
    "Category", // domain axis label
    "Value", // range axis label
    dataset, // data
    PlotOrientation.HORIZONTAL, // orientation
    true, // include legend
    true, // tooltips
    false // urls
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(1.0f);
    // left align the category labels...
    final CategoryAxis axis = plot.getDomainAxis();
    final CategoryLabelPositions p = axis.getCategoryLabelPositions();
    final CategoryLabelPosition left = new CategoryLabelPosition(
    RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT,
    TextAnchor.CENTER_LEFT, 0.0,
    CategoryLabelWidthType.RANGE, 0.30f
    axis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left));
    return chart;
    public void saveimage()
    Image backbuffer;
    ImageObserver observer=null;
    BufferedImage bufferedImage = new BufferedImage (1000,100,BufferedImage.TYPE_INT_BGR );
    // BufferedImage bufferedImage = new BufferedImage ( 1000,100,BufferedImage.TYPE_INT_RGB );
    //      bufferedImage.createGraphics().drawImage( backbuffer, 0, 0,this);
    bufferedImage.createGraphics().drawImage(bufferedImage, 10, 60,observer);
                   try {
                   ImageIO.write( bufferedImage, "jpg", new File ( "image.jpg" ) );
                   } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
    * Starting point for the demonstration application.
    * @param args ignored.
    public static void main(final String[] args) {
    Log.getInstance().addTarget(new PrintStreamLogTarget());
    final BarChart3DDemo2 demo = new BarChart3DDemo2("3D Bar Chart Demo 2");
    demo.pack();
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.saveimage();
    demo.setVisible(true);
    }

    Hi Pradip, its very simple to save the applet as PNG or JPEG. Firstly u dont have to create a function
    saveimage() as u did. delete it. Instead, in the createchart function after the code --------
    final JFreeChart chart = ChartFactory.createBarChart3D(
    "3D Bar Chart Demo 2", // chart title
    "Category", // domain axis label
    "Value", // range axis label
    dataset, // data
    PlotOrientation.HORIZONTAL, // orientation
    true, // include legend
    true, // tooltips
    false // urls
    //append the following code to it
    try {
         ChartUtilities.saveChartAsJPEG(
    new java.io.File("C:/hi.JPEG"), chart, 800, 300);
         } catch (java.io.IOException exc) {
         System.err.println("Error writing image to file");
    //then continue with the rest...BINGO!!! its done...

  • Can assets be images of type jpeg,gif,Tiff,etc... ?

    Hi,
    I am working  on ES2.
    I am able to take PDF file as form to the  my  process. Here  my  new requirement is   in addition to  pdf  I need to take all types  of  images
    say jpeg,gif, and Tiff  as  input to my  process.  But I am not able to do that bcas Workbench only  takes *.pdf as input.
    If you have other extensions  expect  pdf,  while   taking the asset into the  start activity, I  could  not  find that  file in the  application.
    Please help me in this regard how  workbench takes  all image files as inputs into  the  process.
    Thanks
    Praveen.

    Hi Scott,
    Thanks for your reply.
    Yes   I  have to use as image file as form  to the process.
    I am using  Adobe LC ES2.
    Let  me explian my  requirement :  I have  scanned image   and  need to use that image as input to the process i mean image as form  to the process.
    I will invoke the process then  scanned image should come as form  in the  workspace .
    Please help in this regard.
    Thanks
    Praveen.

  • When I "save page as" I also get a folder with gif images, jscript script files and other similar items. how can I stop this.

    When I "save page as" via the file button at the top edge of the page, I also get a folder containing gif images, jscript script files and other similar items. I am not is allowed to delete it unless I also delete the page I need. How can I stop this from happening. is it the way I've configured firefox perhaps.
    == since I installed firefox

    Make sure that you have selected "Web Page, complete" to save the page.

  • How can I use applet to get the desktop image of client

    hi,I have a question to ask u.
    How can I use applet to get the desktop image of client? Now I develop a web application and want user in the client to get his current image of the screen.And then save as a picture of jpeg format ,then upload it to the server?
    I have done an application to get the screen image and do upload file to server in a servlet with the http protocal.

    Since the desktop image is on the client's local hard drive, you'll need to look at trusted applets first.

  • Save to Web for JPEG Does Not Work

    Originally when I installed CS4, save to web worked great.  When I would downsize an image so as to post on the web, it would downsize with ease and I could save it as a JPEG.
    Problem now:  On the right upper corner of the page, I have it set for JPEG.  When I downsize the image to 250, the "GIF" in the far left bottom corner does not convert over to JPEG.  Thus, the image is not getting downsized properly as it used to.
    I still have Photoshop Elements 7 on my computer so now when I want to downsize an image, I work on it first in CS4, get out of CS4 and then go into PS7.
    Again, for weeks, the GIF would turn into JPEG on the far let.  Now in CS4 it does not.
    What do I need to do to fix this?    I have added a screenshot to show my settings in CS4.
    Thanks.

    Are you saying if you select JPEG top right it still says GIF bottom left of the preview window?
    How and where are you "downsizing to 250" ?  250 what?

  • Looking for comprehensive program to create pdf file from gif image

    Hello,
    I'm looking for a program that can transform gif image file into pdf file. It is very importent to keep the same quality of the output document as the original image.
    I've seen Bridge CS5 in action and was very much disapointed, because the original gif image had 2 colors: black and white, took 60k Byte A4 paper size. But the output pdf file became somehow to 700k Byte size. When our proffi tried to lower the ppi or quality bar there was direct impact on the image quality.
    Long time ago Photoshop was able to export images as pdf files and one of the options of the pdf file was to keep the original image as gif, not as jpeg. Because jpeg is very costy format for black-white images and no-one wants to waste memory in vain, so I do not like to save pdf files of 1MB size for an image that takes 100k in gif.
    I do understand that nowdays using Photoshop to save pdf files is not the option anymore, isn't it ?
    What program can you suggest me to use ? I still prefer to use Adobe products, as long as I can, through I'm starting to get scared of sharp decline in quality.
    Thank you in advance.
    sincerely,
    Al

    No, I didn't. The last time I saw it, it was looking just as a regular Reader with a little more options and with an addon to MS-Office, to allow to save MS documents to pdf from inside MS-Office user interface products, and frankly, I do not highly admire there products at all, so I do not have MS-Office installed. But it was also long time ago. If the situation did changed since than,  I will try it.
    Thank you very much.
    I've just tried the Acrobat. It worked great ! Thank you. Just not all the images have options how to save them in pdf file, but that's ok for now

Maybe you are looking for

  • Windows has recovered from an unexpected shutdown(blue screen) windows 7 ultimate 64 bit

    Problem signature:   Problem Event Name: BlueScreen   OS Version: 6.1.7601.2.1.0.256.1   Locale ID: 1033 Additional information about the problem:   BCCode: 50   BCP1: FFFFF90043C98BEC   BCP2: 0000000000000001   BCP3: FFFFF9600025033E   BCP4: 0000000

  • Capturing analog video

    I'm using a Formac Studio DV video capture device to import analog VHS tape into my I.Mac with iMovie 4.0.1. The picture comes in fine but there is a terrible loud staccato noise in playback that blocks out all sound on the tape. What is going on? I'

  • Help with bind variables

    Hello I'm new to .net and I'm trying to work with bind variables I keep getting the ORA-01036: illegal variable name/number error. here's my code, can somebody help me out and show me what am I doing wrong? Protected Sub Page_Load(ByVal sender As Obj

  • Calculating prior months using off-set and crossing to prev year

    Gurus, I am getting current month period based on user entered value and calculating prior month by off-setting current month by 1. it works fine when current month value is greater than 1. If it is 1, prior month does get evaluated as 12 of previous

  • Enable to display tray in Iview

    Hi I have added an iview to Portal under a Role. But when I click on that Iview i am unable to see the Tray as it is not getting displayed because of which i am not able to personalize my iview at runtime........ When I added same Iview in a page and