Results 1 to 6 of 6

Thread: Image Display In Java

  1. #1
    Join Date
    Jan 2009
    Posts
    74

    Image Display In Java

    Hello, recently I have started working on java and while working on it, I have come to know that I am getting problem while displaying image in the page with java programming. If anyone is having program on it, or if anyone is having some or the other details on it, then please provide me solution for it. Thank you in advance.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Image Display In Java

    Hello, I have a code which can help you if you are using the servlet for displaying the image. So, make use of it.
    Code:
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
    { 
    HttpSession HSession = req.getSession();
    ServletContext Servletcon = getServletContext();
    String str = Servletcon.getRealPath("1-30.jpg"); 
    String mtype = Servletcon.getMimeType(str); 
    if (mtype == null) 
    { 
    Servletcon.log("Could not get MIME type of"+ str);
    resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 
    return; 
    } 
    File file = new File(str);
    resp.setContentLength((int)file.length()); 
    FileInputStream in = new FileInputStream(file); 
    resp.setContentType("image / jpeg" );
    BufferedInputStream out2 = new BufferedInputStream(resp.getOutputStream()); 
    byte by[] = new byte[ 32768 ]; 
    int index = in.read( BY, 0, 32768 ); 
    while ( index! = -1 ) 
    { 
    out2.write( BY, 0, Index );
    index = in.read( BY, 0, 32768 ); 
    } 
    out2.flush(); 
    }

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Image Display In Java

    Hello, I think you can achieve this with the tow steps as below:
    1 - to send an image on the server and register it there you need rights or read and write. If you are making a distributed application then it is quiet complicated. So you need to move to an archiving db saved byte.
    2 - You can simply do one thing, in your jsp you can call a link redirecting to a servlet through the web.xml treatment after interrogations that will send the database table in byte with the associated mime types.

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: Image Display In Java

    If you are making use of the swing or awt then you can simply perform it with the help of code below:
    Code:
    Public void paintComponent(Graphics g)
    {
    ImageIcon icon = new ImageIcon("myimage.jpg ");
    Image image = icon.getImage();
    g.drawImage(picture,0,0,null);
    }

  5. #5
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Image Display In Java

    Hey, I have got one code for the displaying image on the page. Make use of it. It is so simple to understand.
    Code:
    import javax.swing .*;
    import java.awt .*;
    Testing class extends JFrame
    {
    Testing ()
    {
    SetTitle ( "Image");
    setSize (800, 500);
    pan = new Panel ();
    getContentPane (). add (pan);
    }
    private JPanel panel;
    }
    class Panel extends JPanel
    {
    Public Panel ()
    {
    Photo = getToolkit (). GetImage ( "photo.jpeg");
    }
    public void paintComponent (Graphics g)
    {
    Super.paintComponent (g);
    int x = 10, y = 10;
    if (photo! = null)
    {
    g.drawImage (image, x, y, this); System.out.println ( "photo");
    }
    }
    private Image image = null;
    }
    public class TestMenu
    {
    Public static void main (String args [])
    Testing (fen = new Testing ();
    fen.setVisible (true);
    }
    }

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Image Display In Java

    This is so simple in java. You just need to make use of the two lines of code below in your program. Just make use of them and solve your problem.
    Code:
    ImageIcon icon = new ImageIcon(picture);
    image = icon.getImage();

Similar Threads

  1. Unable to Display an image in a <div>
    By Constantinee in forum Software Development
    Replies: 5
    Last Post: 06-03-2010, 09:28 PM
  2. Display An Image In A JLabel
    By Amaresh in forum Software Development
    Replies: 5
    Last Post: 08-02-2010, 05:56 PM
  3. Display image icon in java
    By NetworkeR in forum Software Development
    Replies: 3
    Last Post: 14-11-2009, 01:19 PM
  4. Display an image in JPanel
    By S_Asnodkar in forum Software Development
    Replies: 3
    Last Post: 09-05-2009, 10:23 PM
  5. How to display image in PHP Page
    By Aaquib in forum Software Development
    Replies: 2
    Last Post: 21-01-2009, 07:08 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,455,096.12911 seconds with 16 queries