Displaying image from binary data using java

hi there,
i have created a swing applet displays me a url, what the url returns me is the image in binary format, and i want to show the complete image using that binary data
so how do i do it.
some thing like this :
URL url = new URL("http://192.168.1.1:8086/file-storage/download/Zerg.jpg?version_id=35688");
JEditorPane jep = new JEditorPane();
jep.setPage(url);
output is in binary on my applet window.

Hey,
This displays an image from a url, you could check if your url is and image or not using URL.getFileName() and see if it ends in gif jpeg etc. and then display it this way.
hope it helps
Nick Hanlon
import java.awt.*;
import java.awt.Image.*;
import java.awt.Toolkit.*;
import javax.swing.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.swing.text.html.*;
public class SimpleApp extends JFrame {
public static void main(String args[]) {
SimpleApp aFrame = new SimpleApp();
public SimpleApp() {
super("Frame");
/*JEditorPane jep = new JEditorPane();
jep.*/
try {
HTMLEditorKit htmlKit = new HTMLEditorKit();
JEditorPane ep = new JEditorPane();
try {
ep.setEditorKit(htmlKit);
BufferedReader in = new BufferedReader(
new StringReader(
"<HTML><IMG SRC=\"http://developer.java.sun.com/images/chiclet.row.gif\"></HTML>"));
htmlKit.read(in, ep.getDocument(),0);
getContentPane().setLayout(new BorderLayout());
setResizable(false);
getContentPane().add(ep, "North");
pack();
show();
} catch (javax.swing.text.BadLocationException e) {}
} catch (IOException e) {}
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { System.exit(0); }
}

Similar Messages

  • Displaying images from MySQL data base

    I'm currently developing a Master/Detail
    page set. The MySQL table containing the Detail information includes a 'blob'  (MIME: image/jpeg  - Attributes - BINARY) for storing a small image. Under phpmyadmin the images show where applicable.
    In my Detail page I display the results in a table. All the values display except the image.
    I selected Insert > Image
    When the 'Select Image Source' dialogue appeared set 'select file name from' to Data source
    Selected the data base field from the established records set
    I left the 'Format' as 'None'
    Clicked OK
    Have I omitted to set something? How does Dreamweaver or the PHP code know hto to render this field?
    Hope someone can make some suggestions to resolve this.
    Thanks
    Cliff
    Other possible useful info:
    Developing on Windows XP
    Dreamweaver CS5
    all versions of MySQL, PHP, Apache, IE8, Dreamweaver up to date.

    In my desparation this morning
    I even tried to set up a mirror of your example witha separate table (just the 3 fields) and even that didn't work. The Proxy member was the same as yours except that the script was changed to LocalPHP.php . Therefore I presume that the error must have been in the webpage. Unfortunately I've since deleted the code so I can't send a copy of what I used.
    The only suggestions I could suggest that may help others that are novices are (1) suggested code for the webpage (2) a diagram illustrating how the elements link or relate to each other. Hope that is thought helpful.
    Thanks again
    Cliff

  • Displaying image from binary file

    I am converting a image file(jpg) into a binary file and sending it. In the receiving side i got back the binary file and want to display the image in the applet or store the image in a file. while trying to do this i am not able to read the image from the buffer. Below here i have given my code.
    File f= new File("image.jpg");
           FileInputStream fis = new FileInputStream(f);
           byte [] buffer = new byte[(int)f.length()];
           fis.read(buffer,0,buffer.length);
           fis.close();
          File f1 = new File("input.txt");
          int length = buffer.length;
          PrintWriter pw;
           pw = new PrintWriter(new BufferedWriter(new FileWriter(f1)));
          for(int i=0;i<length;i++)
              pw.println(Integer.toBinaryString(buffer));
    pw.flush();
    pw.close();
    converting back to image i get error
    File f1 = new File("inp.txt");
    FileInputStream fis = new FileInputStream(f1);
    buffer = new byte[(int)f1.length()];
    fis.read(buffer,0,buffer.length);
    Toolkit tk = Toolkit.getDefaultToolkit();
    img = tk.createImage(buffer);
    Reply me as early as possible.thanks.

    You have two glaring problems here.
    Firstly, you are writing via writers, which are intended for text and are probably corrupting your data. You want to be using a FileOutputStream.
    Secondly, when reading in you are not checking the number of bytes read and may well not be fully populating your array. You want to change your reading code to something like this,
        buffer = new byte[(int)f1.length()];
        int read = 0;
        while (f1.available() > 0)
            read += fis.read(buffer, read, buffer.length - read);
        }

  • Displaying image from binary code

    I am converting a image file(jpg) into a binary file and sending it. In the receiving side i get the binary file and want to display the image in the applet or store the image in a file. while trying to do this i am not able to read the image from the buffer. Below here i have given my code.
          File f= new File("image.jpg");
           FileInputStream fis = new FileInputStream(f);
           byte [] buffer = new byte[(int)f.length()];
           fis.read(buffer,0,buffer.length);
           fis.close();
          File f1 = new File("input.txt");
          int length = buffer.length;
          PrintWriter pw;
           pw = new PrintWriter(new BufferedWriter(new FileWriter(f1)));
          for(int i=0;i<length;i++)
              pw.println(Integer.toBinaryString(buffer));
    pw.flush();
    pw.close();
    converting back to image i get error
    File f1 = new File("inp.txt");
    FileInputStream fis = new FileInputStream(f1);
    buffer = new byte[(int)f1.length()];
    fis.read(buffer,0,buffer.length);
    Toolkit tk = Toolkit.getDefaultToolkit();
    img = tk.createImage(buffer);
    Reply me as early as possible.thanks.

    You have two glaring problems here.
    Firstly, you are writing via writers, which are intended for text and are probably corrupting your data. You want to be using a FileOutputStream.
    Secondly, when reading in you are not checking the number of bytes read and may well not be fully populating your array. You want to change your reading code to something like this,
        buffer = new byte[(int)f1.length()];
        int read = 0;
        while (f1.available() > 0)
            read += fis.read(buffer, read, buffer.length - read);
        }

  • Insert Image in SharePoint List & Display Image from SharePoint List using C# Pragmatically

    hi 
    i have a share point custom list with the following columns and its types.
    Title--------------->Single line of test 
    FirstName--------------->Single line of test
    LastName--------------->Single line of test
    Description--------------->multiple line of test
    Link--------------->Hyperlink or Picture
    Image--------------->Hyperlink or Picture
    I've to create a visual web part with the following input fields and which can insert following items in the above list columns
     Title                  asp textbox
    First Name         asp textbox
    Last Name        asp textbox
    Description        asp textbox
    Link                  asp textbox
    Image              file upload control
    Submit             asp button
    when i click browse button for image control in above web part it browses image .jpg,jpeg or .png file from my computer into image input field above and when i click submit button it must be submitted in the Image column in the above list.
    i want to know how can i do that in c# pragmatically. 
    i've another visual web part which should read the image from the list in Image column and display it in image control on the web part.
    like this
    <img id="imgdisplay" runat="server" src="" />
    how can i read image from image column through c# pragmatically.

    Hello,
    You can't directly add picture into "Hyperlink or Picture" column because this column takes URL value and image is binary etc. You can first upload that picture into picture library (create new picture or document library) then add that image link
    into that column.
    To add/edit "Hyperlink or Picture" column, SP provided special class called "SPFieldUrl". Wheer you need to pass URL and description as parameter.
    Refer this link for you ref:
    http://stackoverflow.com/questions/23829576/how-to-decide-sharepoint-url-field-is-set-as-hyperlink-or-picture
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • Display image from binary code in web service(Sharepoint portal)

    Hi All,
    We have converted a BAPI into web service.We are able to access it and fetch the data in sharepoint portal. The content which gets published in the sharepoint needs one image also to get displayed.The problem is we have the binary format but we are not able to decode that and display that as image in sharepoint portal.
    We are using VS2003 to make the portal component and then deploy it in sharepoint portal.We are stuck how to decode the binary format and display the image.
    Any Help will be appreicated.
    Regards
    Sachin

    Hi All,
    We have converted a BAPI into web service.We are able to access it and fetch the data in sharepoint portal. The content which gets published in the sharepoint needs one image also to get displayed.The problem is we have the binary format but we are not able to decode that and display that as image in sharepoint portal.
    We are using VS2003 to make the portal component and then deploy it in sharepoint portal.We are stuck how to decode the binary format and display the image.
    Any Help will be appreicated.
    Regards
    Sachin

  • Pasting Image  from Mac clipboard to Java Based Application.

    Hi,
    I am working on "iMac 10.2.7". I need to paste an image from other
    application using "Java version 1.4.1". I am trying to retrieve the image
    from the system clipboard after it is copied from some other application. I
    am pasting the code which illustrates my requirement. It works fine on
    windows. But does not work on Mac.
    On Mac it does not cross the supported data flavor check
    (clipData.isDataFlavorSupported(DataFlavor.imageFlavor) where clipData is
    the Transferable object). It seems Mac has some InputStream instead of Image
    in the clipboard when some image is copied. I tried to read that InputStream
    using ImageIO.read(java.io.InputStream). But that is also returning null.
    Thanks
    Santanu
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import java.awt.datatransfer.*;
    import javax.swing.*;
    public class ClipboardTest extends JFrame implements KeyListener{
         JLabel label;
         static Toolkit kit = null;
         static Clipboard clipboard = null;
         public static void main (String arg[]) {
              kit = Toolkit.getDefaultToolkit();
              clipboard = kit.getSystemClipboard();
              JLabel l = new JLabel();
              JButton button = new JButton("Paste from clipboard");
              final ClipboardTest ct = new ClipboardTest(l);
              ct.getContentPane().add(l,BorderLayout.CENTER);
              ct.getContentPane().add(button,BorderLayout.SOUTH);
              ct.setVisible(true);
         button.addActionListener(
              new ActionListener() {
                   public void actionPerformed(ActionEvent ae) {
                        pasteImage(ct.label);
         button.addKeyListener(ct);
         public ClipboardTest (JLabel l) {
              label = l;
         public static void pasteImage(JComponent jComp) {
                   jComp.setTransferHandler(new ImageSelection());
                   TransferHandler handler = jComp.getTransferHandler();
                   Transferable clipData = clipboard.getContents(null);
              if (clipData != null) {
              if (clipData.isDataFlavorSupported(DataFlavor.imageFlavor)) {
                   handler.importData(jComp, clipData);
         //Key listener methods
         public void keyPressed(KeyEvent e) {
         int c = e.getKeyCode();
         if (c == 86) {
              if (e.isControlDown()) {
                   pasteImage(label);
         public void keyReleased(KeyEvent e) {}
         public void keyTyped(KeyEvent e) {}
    class ImageSelection extends TransferHandler implements Transferable {
         /* DataFlavor instance that holds imageflavor value*/
         private static final DataFlavor flavors[] = {DataFlavor.imageFlavor};
         private Image image;
         public boolean importData(JComponent comp, Transferable transferable) {
         try {
         if (transferable.isDataFlavorSupported(flavors[0])) {
         image = (Image)transferable.getTransferData(flavors[0]);
                   if (comp instanceof JLabel) {
                   ((JLabel)comp).setIcon(new ImageIcon(image));
                   comp.repaint();
                   return true;
         } catch (Exception ignored) {
              ignored.printStackTrace();
         return false;
         // Transferable Interface methods
         public Object getTransferData(DataFlavor flavor) {
         if (isDataFlavorSupported(flavor)) {
         return image;
         return null;
         public DataFlavor[] getTransferDataFlavors() {
         return flavors;
         public boolean isDataFlavorSupported(DataFlavor flavor) {
         return flavor.equals(flavors[0]);

    Here are two commercial options:
    JTwain + JSane
    http://asprise.com/product/jtwain/index.php
    Morena
    http://www.gnome.sk/Twain/jtp.html
    Haven't tested them, so don't no how good they are, nor how easy they are to use on multiple platforms.

  • How to display image from wamp if the data type i use is blob?

    please help me with the problem of displaying image from wamp if data type is blob. Thanks

    Don't store the images in the database. Store the image file names in the database and put the images in a folder.

  • Using flash to display images from sql server or file system

    hello,
    what methods and parameters of the urlloader class we have to use to display images in a flash player if possible..
    also movie should update everytime a new image is added to a database or file
    the images can either be in a file system or in a sql database (if possible)
    does flash comes with an object of this type or we have to create it.
    regards,

    i responded to your duplicate message 4 days ago:
    is it possible to insert and retrieve images from sql server using actionscript.
    you'll need server-side script to query your database and you can use the flash urlloader class to call your script.
    also  is it possible to create a flash scrolling gallery based on images  stored in a database and everytime an image is added it is displayed in  the gallery.
    load the data using the urlloader class and  then load the images.  periodically query the database for new images if  there's no direct way for flash to know a new image was added.

  • How to read a data from USB port using JAVA

    hi all,
    i need to know how to read a data from USB port using java. any API are available for java ?.........please give your valuable ideas !!!!!!!!!
    Advance Thanks!!

    You can do this. Please use this link
    [http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=uHu&q=java+read+data+from+usb+port&btnG=Search&meta=&aq=f&oq=]
    What research did you do of your own? Have you done some testing application and tried yourself??

  • After importing images from my card using LR 5.4, the GPS data does not show in the metadata panel. However, when I look at the imported images using Bridge, the GPS data is visible. Anybody know why LR is not seeing the GPS data? Camera is Canon 6D.

    After importing images from my card using LR 5.4, the GPS data does not show in the metadata panel. However, when I look at the imported images using Bridge, the GPS data is visible. Anybody know why LR is not seeing the GPS data? Camera is Canon 6D.

    Ok, the issue seem to be solved. The problem was this:
    The many hundred files (raw and xmp per image) have been downloaded by ftp in no specific order. Means - a couple of files in the download queue - both raw and xmps. Most of the time, the small xmp files have been finished loading first and hence the "last change date" of these xmp files was OLDER than the "last change date" of the raw file - Lightroom then seem to ignore the existence of the xmp file and does not read it during import.(a minute is enough to run into the problem)
    By simply using the ftp client in a way that all large raw files get downloaded first followed by the xmp files, we achieved that all "last changed dates" of the xmp files are NEWER than the related raw files. (at least not older)
    And then LR is reading them and all metadata information has been set / read correctly.
    So this is solved.

  • To fetch data from MS Outlook using JAVA

    Hi,
    I want to know about any api that helps in fetching MS Outlook data using JAVA code. Any help will be appreciated.
    Thanks
    Rohit

    Hi,
    I have to write data to an Excel sheet through servlet. But I'll also look in to resding data from MS Excel. will tell you if I am able to do that.
    Akhilesh Pathodia

  • Display images from a SQL database

    I want to display images from a SQL database. The images are in a table under a specific column and are stored as a link to the image. How would I display the images from the column in LabVIEW?
    I'm using LabVIEW 2013 version 13 and SQL Server 2012
    Paul Power
    I have not lost my mind, it's backed up on a disk somewhere

    Hi PauldePaor,
    I hope you are well.
    Once you have pulled the data from the database into LabVIEW in a string form (or path), you can simply use the Read BMP File (Or jpg, png depending on the file type) VI.
    More information can be found here:
    http://digital.ni.com/public.nsf/allkb/02971A30F5D8FC6986256A0A004F11A0
    Kind Regards,
    Aidan H
    Applications Engineer
    National Instruments UK & Ireland

  • How to get the context data using java script in interactive forms

    Hi All,
    How to get the context data using java script in interactive forms by adobe,  am using web dynpro java
    thanks.

    Hi venkat,
    Please Refer this link.
      Populating one Drop-Down list from the selection of another Drop-down list
    Thanks,
    Raju.

  • Problem Displaying image from blob

    Hi all,
    I m using,
    Database : 10g Rel 2
    Frontend : DevSuite 10g
    OS : WinXp
    Browser : IE 6
    Problem : In my forms i m displaying images from blob column but some of the images are not displayed. I have tried with all image formats available in combination with all available display quality but no luck. What could be the reason for it and how do i solve it?
    Can anyone help me plz?
    Thnx in advance.
    Imtiaz

    Hello,
    It is very difficult for us to "guess" what images you can read and what others you cannot.
    Maybe you could provide more information on images that are not displayed ?
    What is their native format ?
    Francois

Maybe you are looking for