How do I display a GIF image stored in byte[ ]

I have a bit of sticky problem and am now stuck. I will post a little code in the hopes someone more clever than I can give me a hand
I am using a servlet to grab some data from a user, a web service (still within the servlet) is then called that generates a GIF of the user location as
specified by the address data grabbed from the user input (GET via the url parameters). The byte data is stored in a bean as a byte [ ] and added to the request as an attribute
via request.setAttribute().
I then forward to a jsp page that looks like this:
     <html>
     <head>
     <title>Learn Fast or Perish</title>
     </head>
     <body>
     <center>
     <hr>
     </center>
     <h1>Hello World.</h1>
     <jsp:include page="/display" flush="true"/>
     </body>
     </html>.../display maps to another servlet. The doGet portion of the servlet looks like this:
            //response and request are the HTTPServletResponse/Request doGet parameters
            //ImageByteInformation is my bean holding image info in byte [] format
            ImageByteInformation imageByteInfo = (ImageByteInformation) request.getAttribute("imageByteInformation");
            ImageIcon imageIcon = new ImageIcon(imageByteInfo.getByteData());
            Image image = imageIcon.getImage();
            //create a BufferedImage from the image
            BufferedImage bufferedImage = new BufferedImageCreator().createBufferedImage(image);
            System.out.println("BufferedImage length: " + bufferedImage.getHeight() + "BufferedImage width: " + bufferedImage.getWidth());//400 by 600
            System.out.println("BufferedImage string: " + bufferedImage.toString());
            //prints out: BufferedImage@93afae: type = 2 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=ff000000 IntegerInterleavedRaster: width=600 yada yada
            response.setContentType("/image/gif");
            OutputStream stream = response.getOutputStream();
            ImageIO.write(bufferedImage, "gif", stream);
            stream.close();... i found the code above on line and this is supposed to display a GIF to a web page.
For a while the code was actually prompting if I wanted to download a file of type "/image/gif"?!?
I did download and save it as temp.gif and the image was there when I opened it on my desktop.
Something is in the byte array but I cannot get it to display on the page. So what am I doing wrong.
So my question is this...
How can I display the gif info stored as a byte [] (byte array) in a bean with a jsp page. I thought including a servlet that
writes the bytes to the reponse would but no such luck. Is what I am trying possible? This newbie would greatly appreciate
any advice :)

First of all the following line is a little off:
response.setContentType("/image/gif");should be
response.setContentType("image/gif");What you should do is rather than do an include, try something like the following:
<img src="/display" />If you're telling me that /display is mapped to the servlet that has the doGet you reference, this would be the proper way to do it.
HTH.

Similar Messages

  • How do you display a new image in  webdynpro view?

    How do you display a new image in  webdynpro view?
    Where is the image stored and how do we specify the image path?

    hi ,
    The UI element Image enables you to integrate graphics into the Web application in a format that is processed by the Web Server u2013 for example, GIF, JPG, and PNG format. Height and width of the graphic can be specified using the properties height and width. The graphic is displayed without borders.
    saveur image   as mime
    with Mime Objects u cn upload doc , jpeg, or giff files from our local system into the webdypnpro system .
    Right click on ur component->mime object->import
    In the transaction sicf/bc/webdynpro , u cn check your component name there you can view the mime objects created by you .
    also refer the SAP online help :
    http://help.sap.com/saphelp_crm50/helpdata/en/46/bb182fab4811d4968100a0c94260a5/content.htm
    to knw more abt mime repositories.
    http://help.sap.com/saphelp_nw04/helpdata/en/f3/1a61a9dc7f2e4199458e964e76b4ba/content.htm
    regards,
    amit

  • How to make a Colorful Gif Image for Holi

    How to make a colorful Gif Image for Happy Holi 2014

    Okay, I know this doesn't answer your question, but don't get me wrong. A logo is meant to be the way it was designed - upright, no flipping/ swiveling animation. Why exactly do you want to let your logo turn around?
    If its to grab attention, why dont you consider animating the area on which your logo sits (header)? Or maybe add nice transitive slideshows on your main content area to add more interactivity?

  • Problem at displaying animated gif images !!!!!!!!!!!!

    hello everyone......i am trying to display an animated gif image..............so till far i have no issues on this....
    but i face problem when :
    i have created a class called SimpleGame which extends JPanel....
    public class SimpleGame extends JPanel
    //code
    public void paintComponent(Graphics g)
    //code to draw image
    }now i have written another class with main method
    public class MyGame extends SimpleGame
    public MyGame()
            JFrame frame=new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(800, 600);
            frame.setUndecorated(true);
            frame.setLocationRelativeTo(null);
            frame.getContentPane().add(this);
            frame.setVisible(true);
            this.repaint();
    }so image gets displayed but only one frame of animated image......image that is displayed is static.....since it is a animated gif,,,,,so some how animation is not rendered......only one frame is displayed......
    why is it happening ??
    if i try to display animated image from a single class i mean my paintComponent method and main method is at same class then i do not face problem.....
    but if my paint method is in another class and i am using that method from another class then animation does not get rendered.........
    any help !!!!! please...........

    class SimpleGame extends JPanel
    Image img=new ImageIcon("y.gif");
    public void paintComponent(Graphics g)
    g.drawImage(img,150,150,this);
    }main class//
    class MyGame extends SimpleGame
    public MyGame()
            JFrame frame=new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(800, 600);
            frame.setUndecorated(true);
            frame.setLocationRelativeTo(null);
            frame.getContentPane().add(this);
            frame.setVisible(true);
            this.repaint();
    public static void main(String[] args)
    new MyGame();
    }my image gets displayed.......but only single frame of a animated image....animation is not happening..........

  • Displaying a .gif image and audio in java

    Hi all I need a simple working example that shows how to have Java show a .gif image. I have done several searches but everyone over complicates it and makes in not understandable. I just want a super simple way of displaying an image in java.
    I also need to know how to play an audio clip through java.
    Your help is much appreciated as I have been banging my head for hours now

    Download and install JMF for audio and vedeo clips. JMF is freely available.
    To display an image which is not a difficult task, just tell where you want to display an image.
    regards

  • How to use an animated .GIF image as the texture in Cp4 ?

    Hello all
    I wish to create an animated banner and use it as the texture in Captivate 4.
    As I know texture supports only image formats( JPEG, PNG, GIF,etc). So, I have created a small animation in Photoshop and saved in GIF format and used it as the texture. But when I preview the movie it is displayed as an image but not the animation.
    Is there any solution for this problem?
    Kind regards,
    Kartik Pullela

    1. Instal this package: http://nugetmusthaves.com/Package/WpfAnimatedGif2. Use the code below:
    <Window x:Class="WpfAnimatedGif.Demo.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:gif="http://wpfanimatedgif.codeplex.com"Title="MainWindow"Height="350"Width="525"><Grid><Image gif:ImageBehavior.AnimatedSource="Images/animated.gif"/></Grid>I found this on: http://wpfanimatedgif.codeplex.com/, and this is the useful solution because <MediaElement /> doesn't show the .gif image, and that's pretty strange.

  • Displaying the .png image stored in an byte array

    Hi,
    I have to download an .png image from a server and i have to store it in a byte array and i have to display this byte array in another servlet. I have written the code to get the image from the remote server in a java class. The java class returns the byte array of the image and i have to display that in an servlet.
    If anybody has the code or any refrence to refer please help me..
    Thanks & Regards
    -Sandeep

    I have pasted code for servlet's doGet method which writes image data...
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws
    ServletException, IOException
    HttpSession session = request.getSession(); //taking httpsession
    response.setContentType("image/jpeg");
    ServletOutputStream out = response.getOutputStream(); //taking outputstream of response
    if (rtn.getErrorCode() == 0)
    //this will actually write image file data from where it is being called
    //byte array will contain image data, please load your image into below byte array variable
    byte[] b = new byte[100];
    out.write(b);
    out = null; //making null
    session = null; //making null
    In other servlet, write <img> tag and specify its src attribute to the "name of servlet where u have pasted above code" ..
    Regards,
    Nikhil

  • How can i display a JPG image in a JFrame ?

    sample code would be appreciated
    marvinrouge

    Thanks both : it helped
    here is the code given to all jana-net-guys
    it displays from 1.jpg to 12.jpg
    how can i improve it to displays all .jpg and .gif even if their names ARE NOT like <number>.jpg ???
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    public class PhotoDisplayer extends JFrame implements ActionListener {
         JPanel cp = new JPanel();
         public PhotoDisplayer() {
              getContentPane().setLayout(new BorderLayout());
              setImage(1);
                   cp.add(first);
                   first.addActionListener(this);
                   cp.add(prev);
                   prev.addActionListener(this);
                   cp.add(next);
                   next.addActionListener(this);
                   cp.add(last);
                   last.addActionListener(this);
                   cp.add(exit);
                   exit.addActionListener(this);
              getContentPane().add(cp, BorderLayout.SOUTH);
              pack();
              show();
         public void setImage(String image) {
              ImageIcon ii = new ImageIcon(image);
              if (ii.getIconHeight()>height)
                   height = ii.getIconHeight();
              if (ii.getIconWidth()>width)
                   width = ii.getIconWidth();
              JLabel img = new JLabel(ii);
              JScrollPane sp = new JScrollPane(img);
              getContentPane().removeAll();
              getContentPane().add(sp, BorderLayout.CENTER);
              getContentPane().add(cp, BorderLayout.SOUTH);
              setTitle(image);
              pack();
         public void setImage(int img) {
              setImage("" + img + ".jpg");
         public int image = 1;
         public void moveImage(int dec) {
              if (image+dec>=1 && image+dec<=12) {
                   image += dec;
                   setImage(image);
         public void actionPerformed(ActionEvent event) {
              if (event.getSource()==first)
                   setImage(1);
              if (event.getSource()==prev)
                   moveImage(-1);
              if (event.getSource()==next)
                   moveImage(1);
              if (event.getSource()==last)
                   setImage(12);
              if (event.getSource()==exit)
                   System.exit(0);
         int width = 320;
         int height = 200;
         JButton first = new JButton("First");
         JButton prev = new JButton("Prev");
         JButton next = new JButton("Next");
         JButton last = new JButton("Last");
         JButton exit = new JButton("Exit");
         public static void main(String[] args) {
              new PhotoDisplayer();
         public Dimension getPreferredSize() {
              return new Dimension(width, height);
    }

  • How do I display Canvas Graphic image (Not Iconic button) from jar file

    Hi all,
    I am currently using Forms 10g.
    I have gone through the tutorials on how to add Button Icons into Jar files for web enables forms .....so far so good
    This however does not explain what I actually want to do... since "graphic images are by nature embeded in the for rather than referenced ......so here goes ..
    I have a forms 10g application where all the individual form modules/canvases display a big banner (covering top 20% of the screen). This was done by importing the image straight unto the content canvases. As you know this now becomes a "graphic Image" now embeded(& not referenced by file name) on the canvas. Also bear in mind that this is actually different from an "Image Item" which is a block object.
    I dont know if this is possible, but what steps do i follow to make the image part of a jar file as opposed to my current situation. Please let me know if possible or not so I stop waisting development time looking for answers :)
    Another question is how do i make this jar file a library object so that we can vary the image as we wish
    NB: one other trick which i can think of is to create a giant push button across the screen to display the image and then stick it in a jar file !
    Cheers
    css_jay99

    I don't know about embedded images imported in from the builder, but there is a way to use READ_IMAGE_FILE into a BLOCK.IMAGE_ITEM where the images are all in a jar file stored on the OAS.
    Metalink Note:137397.1 explains it in details.
    Tony

  • How Can I Display Remote Mail Images

    I set my iPhone 3G (iOS4) to NOT automatically load remote image as a means of preventing advertising to spammers that I exist. However, there are notes I receive that I would like to view the remote images - i.e. from my bank, broker and other subscribed to newsletters.
    However, once I turn "automatically load remote images" to off, there seems to be no way to manually load remote images ad-hoc. Am I wrong or have I missed something in the manual? IF there is a way to manually display remote images, can someone tell me how?
    Any help or suggestions would be appreciated.
    TIA

    Sorry I know this is an old thread but thought I would let you know what I have found as I too have been trying to find this out and stumbled across some other threads.
    Looks like this feature is missing and people have been on the case for a few years now! I found some old threads from early 2009, someone even got in contact with apple and the support team didn't know either. So in short even though the manual does indeed say that you can load remote images manually when you have the load remote images setting to off, it looks like we still can't. I am using iOS 4.2.1 and still can't find anywhere where we could load them manually.
    So I found in another thread someone said to send in feedback forms to apple using this link:
    http://www.apple.com/feedback/iphone.html
    I thought this might be a good idea?

  • How can i display a pdf file stored in my KM from webdynpro link ?

    Hi experts,
    i try to open my pdf file stored in km, in the same window of my webdynpro java who has the fire link ?
    i user tow  iviews with inBound and outBound plug, the first one has the fire link and the seconde an iframe witch i set source parameter to my km link where my PDF is stored. Unfortunately, the iFrame don't work correctly, and my PDF is not be displayed
    Can you give some advices ?

    Hi
    Recently in my project I came across a scenario where my Web Dynpro Project had to pick the image from KM. The images to be displayed will be placed in KM. This will avoid loading the images into the Web DynPro project. More over when you have KM installed on your EP server, one can use it for storing backend data and resources. The KM Admin will be undertaking this task of uploading the images to predefined folder structures. Through the application path to the image will be provided dynamically giving you the flexibility to decide which image to be displayed according to the business logic.
    Getting an image from KM Documents to be used in Web Dynpro
    Uploading files to KM repository using Webdynpro APIs
    KM with WebDynpro
    thanks
    Suresh

  • How do I display the entire image by default in Photos app instead of filling the entire screen?

    A lot of the images that I have stored on my phone are taken with another camera. Whenever I view them in the photo app they don't show the full image until I pinch them. Is there a setting that shows the entire image by default? Don't want to be pinching every photo and when other people view my images they often don't realise that there is actually more to see.

    Yes, this is terrible. I am not showcasing the otherwise fine screen but my carefully framed photos. How arrogant from Apple to violently zoom to my pics.
    This needs to be addressed ASAP! Everyone please give feedback http://www.apple.com/feedback/

  • How to use new icons (gif images)  added to the icons folder in forms 6i???

    Hi all,
    I have added some new icons images to the path:
    \\FORMS60\java\oracle\forms\icons
    Now how to show this icons on buttons at run time?

    You mentioned your directory path as \\FORMS60\java\oracle\forms\icons, is this a local directory??? If it's a network directory make sure the directory is accesible by the user.
    Try to create a local directory like C:\my_icons and put your icons in it make sure the directory you have your icons in it is listed in FORMS_PATH registry key string.
    And make sure you icons are of .ico format.
    Tony

  • How to prevent displaying un-corrected image during "Loading..." phase ?

    Is there an option for securely
    not displaying the un-corrected image ?
    (while browsing a large number of images - cache not a real option)
    In my not-so-slow system this ruins my
    personal touch secrets ( ;-) ) .
    Everyone can see my cropping/light adjustments etc.
    Am I alone ?

    Thanks Ian ... a pair of (transparent) glasses and a good bottle might also help !
    As I tried to explain
    preview cache can be huge (I didn't try to copy it from main system to demo laptop)
    and might not guarantee
    that an image will not be displayed "uncorrected".
    I'd prefer a blank placeholder during that "Loading..." phase.Personal choice.
    Would that be a bad idea ?
    BTW my workaround is an export+catalog but for me it defeats
    all the Lightroom DAM beauty.

  • How do you make a GIF image move........

    .....across the screen when your running an applet.
    I've been trying to paint to the screen at positions x y then increment x y and repaint.
    So far I havent been able to find any examples.
    Any help would be appreciated especially example code.
    Thx

    http://java.sun.com/docs/books/tutorial/uiswing/painting/movingImage.html

Maybe you are looking for