Outputting an Image object to jpg or png

Hello,
I have an Image object in my code that is output from another java object. The other java object is from a libarary of GIS classes known as JLOOX.
Anyway, I have an Image stored in the Image object but want to output it to a file. I was looking at the Java Almanac and saw a page http://javaalmanac.com/egs/javax.imageio/Graphic2File.html However, this uses a BufferedImage object.
Is there anything I can do with the Image object to output to a file? Can I convert it to a BufferedImage somehow?

BufferedImage b = new BufferedImage(
source.getWidth(), source.getHeight(),
BufferedImage.TYPE_INT_ARGB  );
b.getGraphics().drawImage( 0, 0, source, null );
ImageIO.write( b, "png" );Thanks, but I have an Image object. How do I write the Image object to ImageIo.write?

Similar Messages

  • Export an image object in a FW PNG

    Hello
    I am following a brilliant tutorial on
    http://www.adobe.com/devnet/fireworks/articles/web_standards_layouts_pt1_05.html
    The tutorial also has resource file in the form of a
    Fireworks PNG.
    The Content layer contains what looks like a JPEG image named
    Highway.
    Is there any way to extract the source image (Highway) intact
    without
    say committing a cropped export?

    SKB wrote:
    > deebs wrote:
    >> Hello
    >>
    >> I am following a brilliant tutorial on
    >>
    http://www.adobe.com/devnet/fireworks/articles/web_standards_layouts_pt1_05.html
    >>
    >>
    >> The tutorial also has resource file in the form of a
    Fireworks PNG.
    >>
    >> The Content layer contains what looks like a JPEG
    image named Highway.
    >>
    >> Is there any way to extract the source image
    (Highway) intact without
    >> say committing a cropped export?
    >
    > If you are just talking about pulling the image out of
    the png, unlock
    > the layers, select the image, copy and paste it into a
    new file.
    >
    > SKB
    Excellent!

  • Does Acrobat Reader for Android support importing signature images? (TIF, JPG, BMP, PNG, etc)

    I have a Galaxy Note 2 and I was looking to import a signature image instead of writing in the scrawl box. 
    Does Acrobat for Android support this like the PC version does?
    Thanks in advance!!

    No, Reader on android does not support it yet. May be something for the future releases.

  • How to output 3D Surface Graph as image file (bmp or jpg or png)

    I'd like to output a graph from the 3D surface.vi module as a regular
    image (like a JPG or BMP).  At this time, I'm going through an
    awkward process of taking a screen cap, then isolating the image with
    photoshop (painful and time consuming).
    Any idea or input would be appreciated.

    RIght-click on the graph and "create...invoke node". On the diagram, select method "get image".
    Save the output of "image data" as JPG, BMP, or PNG using the tools from the "Graphics Formats" palette.
    (The code shows would get a 24bit PNG image)
    See how far you get. Good luck!
    Message Edited by altenbach on 08-12-2005 02:50 PM
    Message Edited by altenbach on 08-12-2005 02:51 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    GetImage.png ‏3 KB

  • Converting a pdf to jpg or png

    Hi all
    I need to convert pdf file page into an image of either jpg or png format.
    Thought pdf-tools.com is offering some java API to do that (which i have tried with trial version, working fine).
    is there any free API either from ADOBE itself or some other open source projects?
    please do let let me know
    Take care
    mahanare

    Hi,
    I've already used iText to produce nice PDF's via a WEb Application using Java Servlets.
    You can import images (jpg, png) into the Pdf you are creating.
    But I'm doubt that you can convert the PDF files created to image files ?
    I would be interested about the functions to use within iText in order to achieve that.
    Thanks
    Philippe

  • Making jpg or png images in Java...

    Hello everyone,
    Can anyone please post a simple class that simply does the following:
    //Create some sort of image
    Graphics g = image.getGraphics();
    g.fillRect(...);
    //Export the image to a jpg file: e.g. a.jpg/a.png
    Thank you

    import java.awt.*;
    import java.awt.geom.Ellipse2D;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class Imaging {
        public static void main(String[] args) throws IOException {
            BufferedImage image = getImage(200, 200);
            // jpg, png, bmp (j2se 1.5), gif (j2se 1.6)
            String fileName = "imaging.jpg";
            saveImage(image, fileName);
            showImage(fileName);
        private static BufferedImage getImage(int w, int h) {
            int type = BufferedImage.TYPE_INT_RGB;
            BufferedImage image = new BufferedImage(w, h, type);
            Graphics2D g2 = image.createGraphics();
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setPaint(new GradientPaint(0,0,Color.red,w,h,Color.orange));
            g2.fillRect(0,0,w,h);
            g2.setPaint(Color.cyan);
            double d = Math.min(w, h)/4;
            g2.fill(new Ellipse2D.Double(w/2-d/2, h/2-d/2, d, d));
            g2.dispose();
            return image;
        private static void saveImage(BufferedImage image, String fileName)
                                              throws IOException {
            File file = new File(fileName);
            int dot = fileName.lastIndexOf(".");
            String ext = fileName.substring(dot+1);
            ImageIO.write(image, ext, file);
        private static void showImage(String fileName) throws IOException {
            BufferedImage image = ImageIO.read(new File(fileName));
            JOptionPane.showMessageDialog(null, new ImageIcon(image),
                                          fileName, JOptionPane.PLAIN_MESSAGE);
    }

  • Export PDF, JPG or PNG images from the mapviewer

    hi,
    I need to export PDF, JPG or PNG images from the mapviewer (Oracle Map client).
    How Can I do it?
    Any Ideas?
    Thanks.

    What I do with xml after calling getMapAsXML function
    Any example?There is a request page in the mapviever configuration webpages, there you can send it to the server and get the image in return.
    or you can write your own programm to send it to the mapviewer servlet using post and progress the response by yourself. Have a look at the mapviewer documentation pdf, there are some examples on the different possible different xml requests.

  • Load jpg in image object

    Hi, i'm trying to create an image object from a jpg file:
    public static void main(String[] args)
    Image img;
    Toolkit t;
    t = Toolkit.getDefaultToolkit();
    img = t.getImage("C:\\Documents and Settings\\m.lipreri\\Desktop\\ciao.jpg");
    System.out.println("img: "+img.toString());
    Frame f = new Frame("Es1_Im");
    ImageFrame IM = new ImageFrame(f,img);
    IM.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e){
    System.exit(0);
    IM.setSize(500,400);
    IM.setVisible(true);
    class ImageFrame extends Frame{
    Frame f;
    Image im;
    //costruttore
    ImageFrame(Frame f,Image im){
    this.f = f;
    this.im = im;
    public void paint(Graphics g){
    g.drawImage(im,0,0,this);
    }but this code doesn't show me anithing in the applet, the image path is right, i've tried to past the path in my browser and i can see the image.
    thnx

    Images get loaded asynchronously, so the image
    probably isn't loaded completely when you try to
    display it. See java.awt.MediaTracker or use
    javax.swing.ImageIcon for loading.I could be wrong, but isn't that the ancient way of doing it? I haven't used MediaTracker in ages. Just use ImageIcon. It's the easist way I know to work with images.

  • Converting a image file (JPG or BMP or any other) to an Image object

    Hello, does anyone have an idea of how I could convert a image file (JPG, BMP, GIF or any other) or even a Corel Draw (.CDR) file to a java Image object?
    Thanks in advance
    Wilson

    Demo:
    import java.awt.image.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.*;
    import javax.swing.*;
    public class ImageResized {
        public static void main(String[] args) throws IOException {
            URL url = new URL("http://today.java.net/jag/bio/JagHeadshot.jpg");
            BufferedImage image = ImageIO.read(url);
            Icon icon = new ImageIcon(image);
            JLabel label = new JLabel(icon);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(label);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    }

  • Photoshop CC wont let me save image with layers as a png or jpg

    I am a beginner and just got Ps last night. I have edited a photo and only put one effect on it, stroke. When i try and save the file as a png or jpg, or really anything other than a psd it tells me that it cannot save the layers the i used in that format. How can i save my edited picture as a png or jpg or convert a psd file to jpg or png?

    If you want transparency for the web there are two choices PNG and GIF. Gif only supports 255 mapped colors when you want transparency and transparent pixels are empty 0% opacity.  PNG supports full color and an Alpha channel for transparency partial transparency is supported. GIF file are very small.
    There are also animated GIF file that browsers support.  While you can create animated png file many browsers don't support them and some browsers like Chrome have an add-on that will support animated png files. Photoshop will save Animated GIF but has no support for animated PNG.

  • How to convert postscript file to jpg or png

    Hi,
    I have to convert the postscript file into jpg or png image and need to display it in GUI.
    Can anyone suggest me how to do it or is there any third party jar available in java so that i can make use of it.
    Thanks & Regards

    i'm not sure what you're trying to do but:
    1.  if you have flash pro, you can open the fla and publish bitmaps of any display object
    2. rename the fla extension to zip and unzip it to utilize its bitmaps.

  • Image convert from jpg to BMP (black & white)

    Hi everybody
    here i am converting a jpg file to 2 bit monochrome image.
    Though this program is making the bmp monochrome image of passing jpg image.
    but the program is hanged in between.
    I don't understand the why it is hanging..though it is generating the result.
    please help me to solve the hanging problem.
    =================================================================================
    source output is:
    C:\j2sdk1.4.1_02\bin>java jaiexp.JAISampleProgram6 aish5.jpg
    1
    2
    FarmHouse2.bmp image
    ERROR: it doesn't finish gracefully....!!
    ==================================================================================
    source code
    package jaiexp;
    import java.awt.Frame;
    import java.awt.image.renderable.ParameterBlock;
    import java.io.IOException;
    import javax.media.jai.Interpolation;
    import javax.media.jai.JAI;
    import com.sun.media.jai.codec.BMPEncodeParam;
    import javax.media.jai.RenderedOp;
    import com.sun.media.jai.codec.FileSeekableStream;
    import javax.media.jai.widget.ScrollingImagePanel;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.awt.image.renderable.*;
    import javax.media.jai.*;
    import javax.media.jai.widget.*;
    import com.sun.media.jai.codec.*;
         * This program decodes an image file of any JAI supported
         * formats, such as GIF, JPEG, TIFF, BMP, PNM, PNG, into a
         * convert it to BMP and save it as bmp file
         public class JAISampleProgram6 {
              /** The main method. */
              public static void main(String[] args) {
                   // Define the source and destination file names.
                   String outputFile = "C:\\j2sdk1.4.1_02\\bin\\jaiexp\\FarmHouse2.bmp";
                   Image bwImage = null;
                   /* Validate input. */
                   if (args.length != 1) {
                        System.out.println("Usage: java JAISampleProgram " + "input_image_filename");
                        System.exit(-1);
                   }//if ends
                   * Create an input stream from the specified file name
                   * to be used with the file decoding operator.
                   Image colorImage = null;
                   try {
                        colorImage = Toolkit.getDefaultToolkit().createImage(args[0]);
                   } catch (Exception e) {
                        e.printStackTrace();
                        System.exit(0);
                   }//try catch ends
                   ImageFilter filter = new BlackWhiteFilter();
                   ImageProducer producer = new FilteredImageSource(colorImage.getSource(),filter);
                   bwImage = Toolkit.getDefaultToolkit().createImage(producer);
                   // Create the ParameterBlock.
                   ParameterBlock pb = new ParameterBlock();
                   pb.add(bwImage);
                   // Create the AWTImage operation.
                   //PlanarImage im = (PlanarImage)JAI.create("awtImage", pb);
                   RenderedOp image1 = (RenderedOp)JAI.create("AWTImage", pb);
                   System.out.println("1");
                   try {
                        FileOutputStream stream = new FileOutputStream(outputFile);
                        System.out.println("2");
                        javax.media.jai.operator.EncodeDescriptor.create(image1,stream,"BMP",null,null);
    System.out.println("3");
                        javax.media.jai.operator.FileStoreDescriptor.create(image1,outputFile,"BMP",null,null,null);
                        System.out.println("4");
                        stream.close();
                   }catch(Exception e){
                        System.out.println("Error:"+e);
                   }//try catch ends
                   System.out.println("5");
              }//fun ends
         }//class ends
         class BlackWhiteFilter extends RGBImageFilter{
         public int filterRGB(int x, int y, int rgb){
         int alpha = (rgb >> 24) & 0xff;
         int red = (int)(((rgb >> 16) & 0xff) * 0.3f);
         int green = (int)(((rgb >> 8) & 0xff) * 0.59f);
         int blue = (int)((rgb & 0xff) * 0.11f);
         int bws = ((red+green+blue) > 127) ? 255 : 0;
         return ((alpha & 0xFF) << 24) | ((bws & 0xFF) << 16) | ((bws & 0xFF) << 8) | ((bws & 0xFF) << 0);
         }//class ends
    thanks in advance.
    regards
    - Deepak
    email: [email protected]
         

    Also keep in mind that there are two definitions of bitmap. You want the 2-color version where each bit represents one color or the other. However, thanks to Microsoft, their bitmaps are really just uncompressed strings of RGB values, storing each pixel in multiple bits.

  • Rotate JPG or PNG

    Hello
    I'm doing a website and a i have to put some images imported
    from a file (by actionscript), the problem is that the images must
    be rotated, but when i rotate the images loses quality, for example
    the lines look like stairs lol. (sorry my bad English, lol). The
    image looks great when strait, but when rotated... :s
    What i'm doing wrong? I import the image to a holder by
    loadMovie, the holder is the exact size of the image and i have
    tried to import jpg and png, and the problem is the same... I have
    tried to put the jpeg quality to the max and the movie quality to
    the best... No changes...
    Can any one help me?

    Hey guys, I've been following this one a little and got to
    thinking about using some methods from the BitmapData class. As it
    turns out, you can increase the quality of the image in rotation
    somewhat, by converting it to a BitmapData Object and then applying
    the rotation, this is a little cumbersome, but does seem to have
    the effect of increasing the image quality. I've set up an example
    comparison code here, using a jpg image at 72 dpi res, from my
    sever, just as an example, try it with some of your own images as
    well and see what you think, I think it shows improvement. Here's
    the code, just set a Stage to 600x400 and it'll do the rest:
    PS. the image on the left has not had the bmp conversion.

  • Output byte[] (image) to JSP page from Servlet - not working - why??

    I'm testing some new code in my servlet. I'm changing the method I use for pulling an image from the db (which is stored in a Blob column) and then displaying it in a Jsp page via <img src="go.callServlet">
    The new way works up until the code that outputs the image (bytes).
    Here's a snippet of the code -
                   rs = stmt.executeQuery("Select image from images");
                   rs.next();
                   Blob blobimage = rs.getBlob(1);          
                   int index = 0;             
                in = blobimage.getBinaryStream();        
                BufferedImage orig = ImageIO.read(in);    
                //resize image
                GraphicsConfiguration gc = getDefaultConfiguration(); //calls method in servlet
                 BufferedImage image = toCompatibleImage(orig, gc); //calls method in servlet                   
                 final double SCALE = (double)max_Width_Large/(double)image.getWidth(null);
                 int w = (int) (SCALE * image.getWidth(null));
                 int h = (int) (SCALE * image.getHeight(null));
                 final BufferedImage resize = getScaledInstance(image, w, h, gc);
                   //convert bufferedimage to byte array
                   ByteArrayOutputStream bytestream = new ByteArrayOutputStream();                                        
                  // W R I T E                                        
                  ImageIO.write(resize,"jpeg",bytestream);                                                                      
                  byte[] bytearray = bytestream.toByteArray();
                  bytestream.flush();
                  res.reset();
                   res.setContentType("image/jpeg");                   
                   while((index=in.read(bytearray))!= -1 ) {                         
                             res.getOutputStream().write(bytearray,0,index);
                   res.flushBuffer();              
                   in.close();     
                   //....               I know for a fact that the process of getting the image as a blob, making a BufferedImage from it, having the BufferedImage resized, and then converted into a byte[] array, works! I tested by putting the result into a db table.
    I just don't understand why it is that as soon as it gets to the code where it should output the image, it doesn't work. Its frustrating:(
    Here's the code I use regularly to output the image to the jsp, works all the time. The reason I've changed the method, is because I wanted to resize the image before displaying it, and keep it to scale without losing too much quality.
    rs = stmt.executeQuery("Select image from testimages");
                   rs.next();
                   Blob blobimage = rs.getBlob(1);
                   int index = 0;             
                in = blobimage.getBinaryStream();
                  int blob_length = (int)blobimage.length();
                  byte[] bytearray = new byte[blob_length];
                  res.reset();
                  res.setContentType("image/jpeg");
                   while((index=in.read(bytearray))!= -1 ) {
                             res.getOutputStream().write(bytearray,0,index);
                   res.flushBuffer();
                   in.close();     
    //...Can someone shed some light on this trouble I'm having?
    Much appreciated.

    I hate to bother you again BalusC, but I have another question, and value your expertise.
    With regards to using the BufferedInput and Output Streams - I made the change to my code that is used for uploading an image to the db, and I hope I coded it right.
    Can you please take a look at the snippet below and see if I used the BufferedOutputStream efficiently?
    The changes I made are where I commented /*Line 55*/ and /*Line 58*/.
    Much appreciated.
         boolean isPart = ServletFileUpload.isMultipartContent(req);
             if(isPart) { //40
              // Create a factory for disk-based file items
              FileItemFactory factory = new DiskFileItemFactory();
              // Create a new file upload handler
              ServletFileUpload upload = new ServletFileUpload(factory);                    
              java.util.List items = upload.parseRequest(req); // Create a list of all uploaded files.
              Iterator it = items.iterator(); // Create an iterator to iterate through the list.                         
              int image_count = 1;
         while(it.hasNext()) {                                                       
              //reset preparedStatement object each iteration
              pstmt = null;
                 FileItem item = (FileItem)it.next();     
                 String fieldValue = item.getName();     
                 if(!item.isFormField()) {//30
              //when sent through form
              File f = new File(fieldValue); // Create a FileItem object to access the file.
              // Get content type by filename.
                 String contentType = getServletContext().getMimeType(f.getName());
                 out.print("contenttype is :"+contentType+"<br>");                    
                 if (contentType == null || !contentType.startsWith("image")) {                               
                     String message = "You must submit a file that is an Image.";
                     res.sendRedirect("testing_operations.jsp?message="+message);
                       return;
              }//if
              //#### Code Update 3/18/09 ####
    /*line 38*/     BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
              BufferedImage bug_lrg_Img = ImageIO.read(bis);                                           
              //code to resize the image;
              BufferedImage dimg = new BufferedImage(scaledW,scaledH,BufferedImage.TYPE_INT_RGB);
              //more code for resizing
              //BufferedImage dimg now holding resized image                           
                  ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
                // W R I T E
                /* Line 55 */     
                   /*  ??? - is a BufferedOutputStream more efficient to write the data */
                   BufferedOutputStream bos = new BufferedOutputStream(bytestream);
                   /*line 58 */     
                   //changed from  ImageIO.write(dimg,"jpg",bytestream);                                  
                   //to
                   ImageIO.write(dimg,"jpg",bos);
              // C L O S E
              bytestream.flush();
                   /* Line 63 */
                   byte[] newimage = bytestream.toByteArray();                    
              pstmt = conn.prepareStatement("insert into testimages values(?)");                              
              pstmt.setBytes(1,newimage);
              int a = pstmt.executeUpdate();     
                   bis.close();
                bytestream.close();
                   bos.close();
                  //...

  • Reading the output from a object running in the local machine.

    Reading the output from a object running in the local machine.
    By using a signed applet i am lunching a small application that returns an image object, how to read that without storing it in the hard disk.
    Which means i need to read the image object return by the local application using applet or jsp .
    i am using tomacat and an html page with an applet with it to lunch the application.

    You can write that image in a binary format using OutputStream for System.out and then read it in your applet.

Maybe you are looking for

  • Blank pages when printing to laserjet pro 200 color MFP M276nw

    When printing to my Laserjet pro 200 color MFP M276nw, the pages are all blank.  I have tried turning the printer off and tried unplugging and replugging.  That didn't help.  Pages are still blank.  Any suggestions? This question was solved. View Sol

  • Error Standard Purchase order form POXPOEPO

    Hi , I am unable to save any information in my PO screen (POXPOEPO) . Actually it's not throwing any error . Whenever we try to close it ask us save . If click ok and save the form and try to exit . Samething happeining again . And also , we see some

  • Audit log trimmer timer job

    HI Audit log trimmer timer job what this job do  I set the sitecollection audit settings to trim the audit data after 7 days  is this job before delete it generate Excel report and save in document library? adil

  • Undeleteable file ? How to get rid of it

    In my trash I have a file thats undeleteable. The file name is ␀␀␀õ␀␀.␀␀ It says zero KB in size and when I get info the file disappears but on the next restart it reappears. Anyone have any idea on what it is ? My info: OSX 10.5.6 15in. Macbook Pro

  • My i phone 3gs during restore got hanged what to do ?

    hai this is manbir I am using i phone 3 gs, today when i plugedit in with i tunes on my laptop it got hanged. When i tried to restore it it says error 1500. Pls tell me what i should do. thanks