How to decoding and encoding PNG and GIF images?

I could decode and encode JPEG images using following create functions which are in com.sun.image.codec.jpeg package.
JPEGImageDecoder decoder = JPEGCodec          .createJPEGDecoder(inputStream);
JPEGImageEncoder encoder = JPEGCodec                    .createJPEGEncoder(outputStream);
But I dont know required package and functions to decode and encode PNG and GIF images. Please help me.

Is the API that hard to follow?
ImageIO.read( file/stream/url)
ImageIO.write( image, format (e.g. PNG, GIF(1), JPEG), file/stream what have you)
1) Not sure if Java supports GIF saving, it might if you install JAI, or Java 6.

Similar Messages

  • Efficiency of decoding and displaying image files?

    BRIEF SUMMARY
    My question is this: can Flash Player download JPG and GIF
    files from a server and rapidly open/decode them, ready for
    display, efficiently and
    entirely 'in memory'?
    Would Flex be a good choice of language for developing a RIA
    that needs to continually download lots of JPG and GIF images
    on-the-fly from the server and render them on the screen? I *don't*
    want my application to thrash the hard disc.
    BACKGROUND
    I am designing a 'rich' web app, and I'm investigating
    whether Flex is the right tool for the job.
    Although Flash's animation features are an obvious selling
    point for implementing my user interface, I also need to do some
    server-side rendering. What I want to do is perhaps a little
    unorthodox: I will be generating lots of GIF and JPG files on the
    fly and these will be streamed to the client (along with other
    application data, e.g. in XML format) to update different parts of
    the on-screen document. In need this to happen very quickly (in
    some cases, creating the effect of animation).
    It happens that JPGs and 16-colour GIFs will be, by far, the
    most efficient formats for streaming the images, because of the
    nature of the application. I could of course send the images in
    some proprietary format, geared for my application, but presumably
    decoding the images would be slow as I would have to implement this
    myself in ActionScript, and so I would be limited by the speed of
    Flex 'bytecode'. (I realise Flash is a lot more optimised than it
    once was, but I am hoping to see a gain from using image formats
    that Flash natively understands!)
    Naturally the internet bandwidth should (in principle) be the
    bottleneck. However, assuming I can get my image files to the
    client on time, want I want to know is:
    how efficient is Flash at loading such files?
    Bearing in mind that I'm not just displaying the occasional
    image -- I will be doing this continuously. Most of the images
    won't be huge, but there will be several separate images per
    second.
    The image files will be a mixture of normal colour JPGs and
    4-bit colour GIFs (LZW-compressed). I know that Flash natively
    supports these formats, but depending on how Adobe have implemented
    their LZW/Huffman decoding and so on, and how much overhead there
    is in opening/processing downloaded image files before they are
    ready to 'blit' to the screen, I imagine this could be pretty fast
    or pretty slow!
    If my client only has a modest PC, I don't want the JPG/GIF
    decoding alone to be thrashing his CPU (or indeed the disc) before
    I've even got started on 'Flashy' vector stuff.
    I'm new to Flash, so are there any 'gotchas' I need to know
    about?
    E.g. Would it be fair to assume Flash Player will do the
    decoding of the downloaded image entirely 'in memory' without
    trying to do anything clever like caching the file to disc, or
    calling any libraries which might slow down the whole process? It
    would be no good at all if the images were first written to the
    client's hard disc before being ready to display, for example.
    Further, if I'm doing something a little out-of-the-ordinary,
    and there is no 'guarantee' that images will be loaded quickly,
    what I'm doing might be a bad idea if a later version of Flash
    Player may (for example) suddenly start doing some disc access in
    the process of opening a newly downloaded image. So, while I could
    just 'try it and see', what I really need is some assurance that
    what I'm doing is sensible and is likely to carry on working in
    future.
    Finally, I imagine JPG/GIF decoding could be something that
    would vary from platform to platform (e.g. for the sake of
    argument, Flash Player for Windows could use a highly-optimised
    library, but other versions could be very inefficient).
    This could be the 'make or break' of my application, so all
    advice is welcome! :) Thanks in advance.

    You need a servlet/jsf component to render the image in the response.
    Look at this: http://www.irian.at/myfaces-sandbox/graphicImageDynamic.jsf

  • How to decode jpeg 2000 compression in dicom image ?

    I'm working on dicom image viewer. How to decode jpeg 2000 compression in dicom image? Please help me. Thanks.

    Illustrator is not a jpg editor.
    There are 2 things you can do....
    Use Live Trace to trace the jpg then adjust the shapes for the track. My guess is this won't work well at all.
    Use the pen tool and draw the path yourself. You can then completely adjust the path all you want.

  • How does decode and case works?

    Hi,
    I want to know how decode and case works? How they process the arguements. Please explain me with some examples.
    Thanks,
    Sarav
    Edited by: 943941 on Jul 3, 2012 1:42 AM

    welcome
    check this link
    https://forums.oracle.com/forums/ann.jspa?annID=1535
    you will find everything you need
    DECODE compares expr to each search value one by one. If expr is equal to a search, then Oracle Database returns the corresponding result. If no match is found, then Oracle returns default. If default is omitted, then Oracle returns null.
    This example decodes the value warehouse_id. If warehouse_id is 1, then the function returns 'Southlake'; if warehouse_id is 2, then it returns 'San Francisco'; and so forth. If warehouse_id is not 1, 2, 3, or 4, then the function returns 'Non domestic'.
    SELECT product_id,
           DECODE (warehouse_id, 1, 'Southlake',
                                 2, 'San Francisco',
                                 3, 'New Jersey',
                                 4, 'Seattle',
                                    'Non domestic')
           "Location of inventory" FROM inventories
           WHERE product_id < 1775;Edited by: user 007 on Jul 3, 2012 2:40 PM

  • How to decode and display jpeg from a bytes stream ?

    Hello.
    I am new to Flex and got stuck on something that I assume has an easy solution.
    I have an RIA application in which I want to display a jpeg image. this image was
    sent on a Web Service message,  as an array of bytes (I just read the jpeg file as
    is and send it to the web application).
    I couldn't figure out a way to decode and display this image at the RIA, using an apropriate component. (Image ?)
    I have seen a few examples where a jpg is loaded from a web server using a url in
    which it's avaliable, but I don't think this is much help to me...
    Your help/example apreciated.

    Thanks.
    I assume you mean passing the bytesArray to Image.load() ?
    Anyway, that's what I did and it worked fine.
    Now I am facing the same issue with playing sounds, which are available on bytesArray.
    I tried to pass the mp3 bytes to the Sound.load(), but it doesn't work, becuase it tries
    to cast it to a URL. do you know by any chance  whether I can achieve that somehow ?
    (I could use prety much any other sound format, if it makes a difference)
    Thanks again.

  • How to decode and display the PDF in ADF application

    Hi All,
    I newbie to Oracle ADF,my requirement is like, In DB table encoded pdf data is available I am able to view the the encodes data in ADF app but I want to decoded pdf. In my app I decoded the encoded data but it comes as text format like' %PDF-1.4
    2 0 obj
    <<
    /CreationDate (D:20121017234301)
    /Keywords <>
    /Author ()' I looking for actual pdf format. Any help.
    Thanks
    Mani

    It would be helpful if you describe what did not work with the sample. The sample reads the pdf from a file whereas you need to load it from a blob in the DB.
    You can use my sample, which need some setup, so don't run it as is, http://tompeez.wordpress.com/2013/05/16/handling-imagesfiles-in-adf-part-4/ which shows how to do this with blobs read from the db.
    Timo

  • Load, crop and saving jpg and gif images with JFileChooser

    Hello!
    I wonder is there someone out there who can help me with a applic that load, (crop) and saving images using JFileChooser with a simple GUI as possible. I'm new to programming and i hope someone can show me.
    Tor

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.filechooser.*;
    import javax.swing.filechooser.FileFilter;
    public class ChopShop extends JPanel {
        JFileChooser fileChooser;
        BufferedImage image;
        Rectangle clip = new Rectangle(50,50,150,150);
        boolean showClip = true;
        public ChopShop() {
            fileChooser = new JFileChooser(".");
            fileChooser.setFileFilter(new ImageFilter());
        public void setClip(int x, int y) {
            clip.setLocation(x, y);
            repaint();
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            if(image != null) {
                int x = (getWidth() - image.getWidth())/2;
                int y = (getHeight() - image.getHeight())/2;
                g2.drawImage(image, x, y, this);
            if(showClip) {
                g2.setPaint(Color.red);
                g2.draw(clip);
        public Dimension getPreferredSize() {
            int width = 400;
            int height = 400;
            int margin = 20;
            if(image != null) {
                width = image.getWidth() + 2*margin;
                height = image.getHeight() + 2*margin;
            return new Dimension(width, height);
        private void showOpenDialog() {
            if(fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
                File file = fileChooser.getSelectedFile();
                try {
                    image = ImageIO.read(file);
                } catch(IOException e) {
                    System.out.println("Read error for " + file.getPath() +
                                       ": " + e.getMessage());
                    image = null;
                revalidate();
                repaint();
        private void showSaveDialog() {
            if(image == null || !showClip)
                return;
            if(fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
                File file = fileChooser.getSelectedFile();
                String ext = ((ImageFilter)fileChooser.getFileFilter()).getExtension(file);
                // Make sure we have an ImageWriter for this extension.
                if(!canWriteTo(ext)) {
                    System.out.println("Cannot write image to " + ext + " file.");
                    String[] formatNames = ImageIO.getWriterFormatNames();
                    System.out.println("Supported extensions are:");
                    for(int j = 0; j < formatNames.length; j++)
                        System.out.println(formatNames[j]);
                    return;
                // If file exists, warn user, confirm overwrite.
                if(file.exists()) {
                    String message = "<html>" + file.getPath() + " already exists" +
                                     "<br>Do you want to replace it?";
                    int n = JOptionPane.showConfirmDialog(this, message, "Confirm",
                                                          JOptionPane.YES_NO_OPTION);
                    if(n != JOptionPane.YES_OPTION)
                        return;
                // Get the clipped image, if available. This is a subImage
                // of image -> they share the same data. Handle with care.
                BufferedImage clipped = getClippedImage();
                if(clipped == null)
                    return;
                // Copy the clipped image for safety.
                BufferedImage cropped = copy(clipped);
                boolean success = false;
                // Write cropped to the user-selected file.
                try {
                    success = ImageIO.write(cropped, ext, file);
                } catch(IOException e) {
                    System.out.println("Write error for " + file.getPath() +
                                       ": " + e.getMessage());
                System.out.println("writing image to " + file.getPath() +
                                   " was" + (success ? "" : " not") + " successful");
        private boolean canWriteTo(String ext) {
            // Support for writing gif format is new in j2se 1.6
            String[] formatNames = ImageIO.getWriterFormatNames();
            //System.out.printf("writer formats = %s%n",
            //                   java.util.Arrays.toString(formatNames));
            for(int j = 0; j < formatNames.length; j++) {
                if(formatNames[j].equalsIgnoreCase(ext))
                    return true;
            return false;
        private BufferedImage getClippedImage() {
            int w = getWidth();
            int h = getHeight();
            int iw = image.getWidth();
            int ih = image.getHeight();
            // Find origin of centered image.
            int ix = (w - iw)/2;
            int iy = (h - ih)/2;
            // Find clip location relative to image origin.
            int x = clip.x - ix;
            int y = clip.y - iy;
            // clip must be within image bounds to continue.
            if(x < 0 || x + clip.width  > iw || y < 0 || y + clip.height > ih) {
                System.out.println("clip is outside image boundries");
                return null;
            BufferedImage subImage = null;
            try {
                subImage = image.getSubimage(x, y, clip.width, clip.height);
            } catch(RasterFormatException e) {
                System.out.println("RFE: " + e.getMessage());
            // Caution: subImage is not independent from image. Changes
            // to one will affect the other. Copying is recommended.
            return subImage;
        private BufferedImage copy(BufferedImage src) {
            int w = src.getWidth();
            int h = src.getHeight();
            BufferedImage dest = new BufferedImage(w, h, src.getType());
            Graphics2D g2 = dest.createGraphics();
            g2.drawImage(src, 0, 0, this);
            g2.dispose();
            return dest;
        private JPanel getControls() {
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.weightx = 1.0;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            panel.add(getCropPanel(), gbc);
            panel.add(getImagePanel(), gbc);
            return panel;
        private JPanel getCropPanel() {
            JToggleButton toggle = new JToggleButton("clip", showClip);
            toggle.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    showClip = ((AbstractButton)e.getSource()).isSelected();
                    repaint();
            SpinnerNumberModel widthModel = new SpinnerNumberModel(150, 10, 400, 1);
            final JSpinner widthSpinner = new JSpinner(widthModel);
            SpinnerNumberModel heightModel = new SpinnerNumberModel(150, 10, 400, 1);
            final JSpinner heightSpinner = new JSpinner(heightModel);
            ChangeListener cl = new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    JSpinner spinner = (JSpinner)e.getSource();
                    int value = ((Number)spinner.getValue()).intValue();
                    if(spinner == widthSpinner)
                        clip.width = value;
                    if(spinner == heightSpinner)
                        clip.height = value;
                    repaint();
            widthSpinner.addChangeListener(cl);
            heightSpinner.addChangeListener(cl);
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(2,2,2,2);
            gbc.weightx = 1.0;
            panel.add(toggle, gbc);
            addComponents(new JLabel("width"),  widthSpinner,  panel, gbc);
            addComponents(new JLabel("height"), heightSpinner, panel, gbc);
            return panel;
        private void addComponents(Component c1, Component c2, Container c,
                                   GridBagConstraints gbc) {
            gbc.anchor = GridBagConstraints.EAST;
            c.add(c1, gbc);
            gbc.anchor = GridBagConstraints.WEST;
            c.add(c2, gbc);
        private JPanel getImagePanel() {
            final JButton open = new JButton("open");
            final JButton save = new JButton("save");
            ActionListener al = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    JButton button = (JButton)e.getSource();
                    if(button == open)
                        showOpenDialog();
                    if(button == save)
                        showSaveDialog();
            open.addActionListener(al);
            save.addActionListener(al);
            JPanel panel = new JPanel();
            panel.add(open);
            panel.add(save);
            return panel;
        public static void main(String[] args) {
            ChopShop chopShop = new ChopShop();
            ClipMover mover = new ClipMover(chopShop);
            chopShop.addMouseListener(mover);
            chopShop.addMouseMotionListener(mover);
            JFrame f = new JFrame("click inside rectangle to drag");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new JScrollPane(chopShop));
            f.getContentPane().add(chopShop.getControls(), "Last");
            f.pack();
            f.setLocation(200,100);
            f.setVisible(true);
    class ImageFilter extends FileFilter {
        static String GIF = "gif";
        static String JPG = "jpg";
        static String PNG = "png";
        // bmp okay in j2se 1.5+
        public boolean accept(File file) {
            if(file.isDirectory())
                return true;
            String ext = getExtension(file).toLowerCase();
            if(ext.equals(GIF) || ext.equals(JPG) || ext.equals(PNG))
                return true;
            return false;
        public String getDescription() {
            return "gif, jpg, png images";
        public String getExtension(File file) {
            String s = file.getPath();
            int dot = s.lastIndexOf(".");
            return (dot != -1) ? s.substring(dot+1) : "";
    class ClipMover extends MouseInputAdapter {
        ChopShop component;
        Point offset = new Point();
        boolean dragging = false;
        public ClipMover(ChopShop cs) {
            component = cs;
        public void mousePressed(MouseEvent e) {
            Point p = e.getPoint();
            if(component.clip.contains(p)) {
                offset.x = p.x - component.clip.x;
                offset.y = p.y - component.clip.y;
                dragging = true;
        public void mouseReleased(MouseEvent e) {
            dragging = false;
        public void mouseDragged(MouseEvent e) {
            if(dragging) {
                int x = e.getX() - offset.x;
                int y = e.getY() - offset.y;
                component.setClip(x, y);
    }

  • Jpeg and gif images are not fuzzy

    How can I import jpeg and gif files so that they are crisp and not fuzzy?  I have Lifecycle Designer 7.0
    T

    Look at the bottom of this page as well [http://carlback.blogspot.com/2007/12/apex-and-3rd-party-js-libraries.html]
    Patrick Wolf
    Carl,
    the only drawback with #WORKSPACE_IMAGES# and #APP_IMAGES# is that it doesn't get cached by the browser. So each page request will transmit the hole file again. A caching option for the "Static Files" in the Shared Components would be nice :-)
    About lazy loading with the #WORKSPACE_IMAGES#. I could think about a mod_rewrite rule which translates the additional file request of the JS library into a valid request for APEX.
    Carl Backstrom
    In 3.1 we emit a last modified header now for uploaded files so that should help with browser caching.
    I wonder if anything's changed since then.
    Kofi

  • How to store and retrive images in oracle database

    hi,
    i am interested in storing some students pictures ( photos) into my oracle database, and i want to know since the images are considered as binary data and since BLOB and CBLOB and supported by oracle, how to insert and to select the picture from oracle from my swing-based application?
    does anyone have a complete sample or tutorial doing that well!!
    thx

    Mira este link,
    hay varios articulos interesantes.
    http://www.oracle-base.com/articles/9i/Articles9i.php
    tambien puedes consultar este link
    http://tahiti.oracle.com/pls/db92/db92.homepage
    completa los coampos solicitados con la palabra "Images"
    hay un manual de LOBs muy completo

  • How to upload and download image?

    hi,
    can anyone send me links  how to to upload and download image to and from sever
    Here i am using amfphp,mysql,php
    i have an button and textfield.when i clicked on the button the path will be stored into database and image will be
    stored into server folder.Similarly for edit i want to display that image to end user.How to do that?

    hi,
    you need to first bring the image into your sap system.
    that you can achieve by right clicking you application and then clicking on create mime object.
    check out this link too:
    Re: how to upload an image file(or any file) in mime using file upload ui eleme
    then you have to insert an image ui element in your view.
    check out the link:
    http://help.sap.com/saphelp_nw04/helpdata/en/f3/1a61a9dc7f2e4199458e964e76b4ba/content.htm
    according to you req i think you need to upload and download the image file in your system using a button. so for this you can follow the below link:
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/00062266-3aa9-2910-d485-f1088c3a4d71
    hope this will surely help you!!!
    thanks & regards,
    punit raval.
    Edited by: punit raval on Jun 24, 2009 9:56 AM

  • How to insert and view images from oracle using jsf

    Can anyone please give me some code example or link of article explaining that how can i insert and view images to/from oracle using jsf?
    Thanks in advance.

    You mean you want to view image data stored in the database, right?
    Create a servlet that streams the image data to the response (setting the appropriate content-type), then reference this servlet in your img tag. Here is an example:
    http://balusc.blogspot.com/2007/04/imageservlet.html
    Storage is something different. What exactly don't you understand there? Perhaps you want a file upload component?

  • Firefox lags with youtube and .gif images

    Everytime I try to watch a video on YouTube or even on other sites FireFox lags aprox every 10 seconds. Is annoying. The same thing happens with .gif images.
    How can I fix this?
    == This happened ==
    Every time Firefox opened
    == Always

    This can be a problem with session restore.
    Firefox stores session data every 10 seconds to make it possible to restore a crashed session.
    If you have (security) software that interferes with that or have many tabs open then that cause cause a delay.
    Some have reported that increasing the session store saving interval worked for them.
    See:
    http://kb.mozillazine.org/browser.sessionstore.interval
    http://kb.mozillazine.org/Session_Restore

  • IIS (proxy) plug-in and gif images

    I was wondering if anyone has run into the problem of not having the linked images load/show up that within a jsp going thru the iis proxy plug-in setup?
              

    Hello,
              If the GIF images are located on the WebLogic Server, then you need to setup
              IIS to proxy .gif to WebLogic as well.
              It is recommended to place the GIf images on IIS as static content should be
              served by IIS for performance reasons.
              Regards,
              Eric
              "Steve Kruse" <[email protected]> wrote in message
              news:3acd5b9c$[email protected]..
              > I was wondering if anyone has run into the problem of not having the
              linked images load/show up that within a jsp going thru the iis proxy
              plug-in setup?
              

  • How to get and display image file through servlet

    If I've got a jpg file on the server..
    How can I use servlet to return that image via the following calling method
    /displayfile?filename=image.jpg
    the image.jpg in the server will return
    I know that I need to set the content type to image/jpeg
    after that, how can I return the image file to browser?

    - Get the "file" Parameter from the URL QueryString
    - check if the File specified exists on your filesystem
    - read in the jpg from the file (best would be binary)
    - set the right Mime Type (as you already wrote)
    - write the filecontent to the ServletOutput as you would do with any other content
    - that's it.

  • How to  upload and display image using bsp application

    hi
    I  just wants to know that
    1- how to  upload image from BSP page with attachment into sap server .?
    2-how to display image in to BSP page(webpage).
    thanks

    Hello Gupta Prashant,
    Just to upload and display an image, import image in MIME repository. Not only still images but also flash files can also be uploaded in the MIME repository. Once you import the image in it, use normal html code for image call;
    <img src = "file.jpg/gif" width=  height=>
    Besides it, if your requirement is to store the image in the database and fetch it based on specified field-name, then you have to go for BLOBs i.e Binary Large Object, using this you can also store images, videos, pdfs, applications in the database.
    MBLOB - Medium BLOBs store videos and pdfs,
    LBLOB  - Large BLOBs store movie files and applications.
    You have got 2 ways to use it; some databases store BLOB objects into themselves and some store the path of the BLOB object maintained on the FTP server.
    You can also implement it in ABAP;
    read the following link and practice the tutorial;
    [ Use of MIME Types|http://help.sap.com/saphelp_45b/helpdata/en/f1/b4a6c4df3911d18e080000e8a48612/content.htm]
    also check this
    [TYPES - LOB HANDLE|http://help.sap.com/abapdocu/en/ABAPTYPES_LOB_HANDLE.htm]
    And looking at your question, in order to upload an image, you can make use of FILEUPLOAD tag provided by HTMLB.
    Step 1: FILEUPLOAD provides a browse button to choose desired image file.
    Step 2: Store that image in database using BLOBs.
    Step 3: Retrieve the image using normal select query and display it on the screen.
    Hope it helps you,
    Zahack

Maybe you are looking for