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

Similar Messages

  • 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.

  • I am trying to use photomerge compose.  I open one standard jpeg image and one image that is my business logo in a png format.  When I select the png image, to extract the logo from it, it appears as all white and will not allow me to select the logo from

    I am trying to use photomerge compose.  I open one standard jpeg image and one image that is my business logo in a png format.  When I select the png image, to extract the logo from it, it appears as all white and will not allow me to select the logo from it.  It has worked in the past but I downloaded the update today and photomerge will not work correctly.  Any ideas?

    hedger,
    How do you expect anyone to help when we don't know a darned thing about the file, abut your setup, exact version of Photoshop and your OS, machine specs, etc.?
    BOILERPLATE TEXT:
    Note that this is boilerplate text.
    If you give complete and detailed information about your setup and the issue at hand,
    such as your platform (Mac or Win),
    exact versions of your OS, of Photoshop (not just "CS6", but something like CS6v.13.0.6) and of Bridge,
    your settings in Photoshop > Preference > Performance
    the type of file you were working on,
    machine specs, such as total installed RAM, scratch file HDs, total available HD space, video card specs, including total VRAM installed,
    what troubleshooting steps you have taken so far,
    what error message(s) you receive,
    if having issues opening raw files also the exact camera make and model that generated them,
    if you're having printing issues, indicate the exact make and model of your printer, paper size, image dimensions in pixels (so many pixels wide by so many pixels high). if going through a RIP, specify that too.
    etc.,
    someone may be able to help you (not necessarily this poster, who is not a Windows user).
    a screen shot of your settings or of the image could be very helpful too.
    Please read this FAQ for advice on how to ask your questions correctly for quicker and better answers:
    http://forums.adobe.com/thread/419981?tstart=0
    Thanks!

  • Dreamweaver CS4- I can't get my site to display the proper image.

    I have a Dreamweaver CS4 Template with an editable area for a header image. I have already assigned a new image to all the header regions but when I moved the site to the web host the pages will only display the Default header image from the template in the editable region, even though when I check the file name in the Modify Templates window it displays the proper name, but displays the wrong image.
    What is wrong? any help would be greatly appreciated.
    thanks.

    Did you upload the new header image?
    This one is currently being displayed.
    http://stjohnvianney.net/parish_assets/Header_Church_img.jpg
    NOTE: Your email link is wrong.  It points to a file on your local hard drive.
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb

  • I have a problem with loading the PNG image

    I have a problem with loading the PNG image from site. For ex. go to icefilms com and is starts to load png like crazy CPU is huge and you can not shut down Firefox at least a minute. This is not just in this site but whit any one whit lots of pictures.
    Image from firefox: Picture [http://img836.imageshack.us/img836/9910/7312011103147pm.jpg 1] [http://img28.imageshack.us/img28/8505/7312011103249pm.jpg 2] [http://img706.imageshack.us/img706/5615/7312011103348pm.jpg 3 ][http://img827.imageshack.us/img827/8483/7312011103533pm.jpg 4]
    This is my Task Manager [http://img217.imageshack.us/img217/5715/7312011103621pm.jpg 1]
    - I try safe mode, same thing
    -All addons and plugins are ok
    Any idea why is this so big problem.

    i did both of them, but still the while sending the mail the diolog box is not showing up and also the spelling and grammer does not do the spelling check. 
    This problem just started for about 3 to 4 days now.  earlier it was working normally.

  • Displaying the layer image in a Flex panel

    Hi,
    I need to display the contents (image) of the active layer in a Flex panel. Was thinking along the lines of saving the layer as a temporary image and then loading it into an Image control. But is there a better/less messy way than this?

    I want to know this too.

  • How can i  set the .PNG image on JButton

    hi deras
    i try my best to set the png image on button instead of gif or JPEG.
    plz help me as soon as possible.
    thanking u i remain.

    Try harder.import javax.swing.*;
    import java.io.IOException;
    import java.net.URL;
    public class TestPNGButton {
         public static void main(String[] args) {
              try {
                   final JFrame frame = new JFrame(TestTextArea.class.getName());
                   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   JButton button = new JButton(new ImageIcon(
                             new URL("http://java.sun.com/docs/books/tutorial/ui" +
                                       "swing/components/example-1dot4/images/pngIcon.png")));
                   frame.setContentPane(button);
                   SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                             frame.pack();
                             frame.show();
              } catch (IOException e) {
                   e.printStackTrace();
    }It works for me.

  • How do i convert an image object to a byte array ?

    Hi
    how do i convert an image object into a byte array
    early reply apperciated

    Oh sorry my method and the other method need to have the pixels from the Image passed to them which you get my using pixelgrabber:
    //create width and height variables from image
              int w = img.getWidth(this);
              int h = img.getHeight(this);
              //retrive picture from image
              int[] pix = new int[w * h];
              PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pix, 0, w);
              try{ pg.grabPixels();
              } catch (InterruptedException ioe) {
                   System.err.println("Interrupted");
              if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
              System.err.println("image fetch aborted or errored");
              }

  • My program always displays the same image, even when I change th image file

    I'm making a program that chooses an image file from a dialog, resize it and copy it into a folder. When the image is needed to be displayed, the image file is read and a JLabel displays it on screen.
    When I upload the first image, everything works fine. The problem appears when I upload another picture: the displayed image is still the first image, even when the old file doesn't exist anymore (because it has been overwritten). It looks like the image has been "cached", and no more image are loaded after the first one.
    This function takes the image picture chosen by the user, resizes it, and copy it into the pictures folder:
        private void changeProfilePicture() {
            JFileChooser jFileChooser = new JFileChooser();
            jFileChooser.setMultiSelectionEnabled(false);
            jFileChooser.setFileFilter(new ImageFileFilter());
            int result = jFileChooser.showOpenDialog(sdbFrame);
            if (JFileChooser.APPROVE_OPTION == result) {
                try {
                    //upload picture
                    File file = jFileChooser.getSelectedFile();
                    InputStream is = new BufferedInputStream(new FileInputStream(file));
                    //resize image and save
                    BufferedImage image = ImageIO.read(is);
                    BufferedImage resizedImage = resizeImage(image, 96, 96);
                    String newFileName = sdbDisplayPanel.getId() + ".png";
                    String picFolderLocation = db.getDatabaseLocation() + "/" +
                            PROFILE_PICTURE_FOLDER;
                    java.io.File dbPicFolder = new File(picFolderLocation);
                    if(!dbPicFolder.exists())  {
                        dbPicFolder.mkdir();
                    String newFilePath = picFolderLocation + "/" + newFileName;
                    File newFile = new File(newFilePath);
                    FileOutputStream fos = new FileOutputStream (newFilePath);
                    DataOutputStream dos = new DataOutputStream (fos);
                    ImageIO.write(resizedImage, "png", dos);
                    dos.close();
                    fos.close();
                    //set picture
                    sdbDisplayPanel.setImagePath(newFilePath);
                } catch (IOException ex) {
                    System.err.println("Could'nt print picture");
                }This other class actually displays the image file in a JLabel:
        public void setImagePath(String imagePath) {
            count++;
            speaker.setImagePath(imagePath);
            this.imagePath = imagePath;
            if(imagePath != null)   {
                //use uploaded picture
                try {
                    File tempFile = new File(imagePath);
                    System.out.println(tempFile.length());
                    java.net.URL imgURL = tempFile.toURI().toURL();
                    ImageIcon icon = new ImageIcon(imgURL);
                    pictureLbl.setIcon(icon);
                    // Read from a file
                } catch (IOException ex) {
                    Logger.getLogger(SDBEventClass.class.getName()).log(Level.SEVERE, null, ex);
            else    {
                //use default picture
                URL imgURL = this.getClass().getResource("/edu/usal/dia/adilo/images/noProfile.jpg");
                ImageIcon icon = new ImageIcon(imgURL, "Profile picture");
                pictureLbl.setIcon(icon);
        }

    When you flush() the image, you don't need to construct a new ImageIcon each time, a simple repaint() will suffice.
    Run this example after changing the URL to an image you can edit and update while the program is running.import java.awt.BorderLayout;
    import java.awt.Image;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.swing.*;
    public class FlushImage {
       Image image;
       JLabel label;
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
                new FlushImage().makeUI();
       public void makeUI() {
          try {
             ImageIcon icon = new ImageIcon(new URL("file:///e:/java/dot.png"));
             image = icon.getImage();
             label = new JLabel(icon);
             JButton button = new JButton("Click");
             button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                   image.flush();
                   label.repaint();
             JFrame frame = new JFrame("");
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             frame.add(label, BorderLayout.NORTH);
             frame.add(button, BorderLayout.SOUTH);
             frame.pack();
             frame.setLocationRelativeTo(null);
             frame.setVisible(true);
          } catch (MalformedURLException ex) {
             ex.printStackTrace();
    }db

  • Why aren't my CSS and div tag boxes displaying the background images I'm plugging in?

    I'm using the CSS dialog boxes to places images via the background image option into my dreamweaver site. Everything looks fine in dreamweaver but when I view it any of the browsers, two of the images I've place as div tag background images don't work....the overal background image of the site works, but these don't show up ....
    here's my code if it helps to answer
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Main</title>
    <style type="text/css">
    body {
    background-image: url(images/realgrade.jpg);
    background-repeat: repeat-x;
    text-align: center;
    html, body {
    margin-right: 0px;
    margin-bottom: 0px;
    margin-left: 0px;
    margin-top: 0px;
    padding-top: 25px;
    #wrapper {
    width: 930px;
    text-align: left;
    margin-top: 0px;
    margin-right: auto;
    margin-bottom: 0px;
    margin-left: auto;
    position: relative;
    background-image: url(file:///Macintosh%20HD/Users/jimmymoreira/Unnamed%20Site%204/images/possible%20image. jpg);
    background-repeat: no-repeat;
    #header {
    height: 192px;
    width: 237px;
    background-image: url(images/logo_fill.jpg);
    background-repeat: no-repeat;
    position: absolute;
    left: 35px;
    top: -25px;
    #mainNav {
    background-color: #33F;
    height: 200px;
    width: 272px;
    float: left;
    margin-top: 233px;
    #maincontent {
    height: 600px;
    width: 608px;
    float: right;
    margin-bottom: 45px;
    padding-right: 25px;
    background-repeat: no-repeat;
    background-position: center 270px;
    background-image: url(file:///Macintosh%20HD/Users/jimmymoreira/Unnamed%20Site%204/images/opaqueMaincontent .png);
    #sidebar {
    background-color: #F36;
    height: 250px;
    width: 272px;
    clear: left;
    float: left;
    #footer {
    height: 525px;
    width: 870px;
    clear: both;
    padding-top: 45px;
    padding-right: 30px;
    padding-bottom: 30px;
    padding-left: 30px;
    background-image: url(images/footer_image.jpg);
    background-repeat: no-repeat;
    margin-top: 45px;
    </style>
    </head>
    <body>
    <div id="wrapper">
      <div id="header">
        <p> </p>
        <p> </p>
        <p> </p>
      </div>
      <div id="mainNav">
    <p> </p>
    </div>
      <div id="maincontent"></div>
      <div id="sidebar"></div>
      <div id="footer"></div>
    </div>
    </body>
    </html>
    here's what I'm going for
    here's what I'm getting in the browser
    Please help!

    Your image files are pointing to your hard drive, not your server.  You have this
    background-image: url(file:///Macintosh%20HD/Users/jimmymoreira/Unnamed%20Site%204/imag es/opaqueMaincontent.png);
    and you should have this
    background-image: url(imag es/opaqueMaincontent.png);
    Also, is your images file named imag es?
    Gary

  • Why doesn't Photoshop display the full image on open?

    I'm using Photoshop CC on a MacBook Pro with OS X 10.9.2 and an external monitor, and when I open an image, it is partially hidden by the display window - scroll bars appear along the sides of the image display window. It's a little annoying, but hasn't been a big problem - I can just resize the display window. However, when I run a script to place an image, the image is placed in the center of the window rather than the center of the actual image, so the placed image ends up being cropped off the base image. The images I'm using are not large, 650 x 296 pixels at 72dpi, and take up less than 1/4 of the screen at 100%.
    I've tried adding scripts like http://www.ps-scripts.com/bb/download/file.php?id=10&sid=adf04fde6ee2c 103cddbc41220d6c3b3 and http://morris-photographics.com/photoshop/scripts/view-pixels.html, but they had no impact on the opening of the files.
    How can I get the display window to show the entire image automatically when I open it? Thank you.

    I'm not familiar with coding script - do you have a suggestion as to what I might try? The Fit to Screen script works when I open an image from Finder, but it does not activate when I run a Automate Batch. The placed image still gets cropped.

  • Where are the wallpaper images stored?

    Hello,
    Does anyone know where the wallpaper image files are stored on the hard drive?
    Thanks.

    Run this Applescript:
    Click here to launch Script Editor.
    tell application "Finder" to reveal desktop picture

  • 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/

  • IPad retina via iOS simulator can not display the whole image (2048x1536)

    Hi,
    I am developing cartoon ebooks with iOS simulatort 7.0. The target device is iPad retina. I use the image whose size is 2048x1356. After building by iOS simulator--iPad retina, only center part of image was displayed. I hope to show the whole image with simulator, how should I do?
    Thanks!

    You would do better to ask your question on the developers' forum. We are but simple users here....

  • My Firefox display the converted image

    Why in my firefox the displayed image converted? Need Help! If i move my cursor to the image, This pop ' Shift + R improves the quality of this image. Shift+A improves the quality of all images on this page'. It's so disturbme. I can't see the good image. HELP ME!!

    You may have an ISP that sends images compressed to speed up the transfer and adds a script to each page to make it possible to see images in the original quality.
    See [tiki-view_forum_thread.php?forumId=1&comments_parentId=197606]

Maybe you are looking for

  • Ipod Nano not recognized on my computer

    My iPod Nano doesn't show up on My Computer or in the ITunes store under devices. A popup recommends reconnecting the device but it does not help.  It then says to uninstall and reinstall Itunes. This device used to be recognized on a different pc bu

  • Regarding Sap Report Painter Tutorials

    Hi All, I donot know whether it is right Forum to Post message. Sorry if I am wrong. Can anyone tell me some Link for good tutorial of Report Painter, As I have to work on that. Also I am beginner in Report painter Regards, Rishi Bhatia

  • BEGINNING POST-PROCESSING

    Hello Good People, I am new to this Forum, and new to using Oracle XML - to develop Oracle Reports for my employee. I would be grateful if you can assist me find a permanent solution to the problem below: ------------- 1) PUBLISH -------------* Begin

  • Red Slider will not appear when trying to force reboot

    Hello, I found my old ipod touch and it says Disabled connect to Itunes. I do not have my origional pc to re-synch so i am trying to do the force restore. However i cannot get the red slider to appear in order to turn ipod off. I have tried numerous

  • ISE WLC Port bounce with NAC

    Im having trouble renewing the IP address after a VLAN change after NAC Agent finishes its posture, the flow is as follows: 1. Wireless client access into the network, is 802.1x 2. NAC Agent succesfully validates posture and Coa is issued 3. I see th