many questions about displaying a PPM image in a Swing component

Discussion in 'Java' started by Marteno Rodia, Jun 23, 2009.

  1. Hello everyone,
    I'm building a GUI for an application and I want to display an image
    as a part of a JFrame. Which component should I use for this purpose?
    I thought I must implement my own component and overload its paint()
    method, but I've found ImageIcon. Of course, first I need to read in
    an image from a file to an Image object. It is possible to use
    BufferedImage class and its read() method... But I must use an
    uncompressed image in the PPM format (don't ask why, it's a
    requitement). Apparently, the read() method won't recognize this
    format. So what should I do?

    Unfortunately, I must implement reading the file by myself (it's not a
    very complicated task). I think it's perhaps possible to "pull out"
    the graphics context for the Image object and then to drow an image
    pixel by pixel... But how to do it in detail?

    MR
     
    Marteno Rodia, Jun 23, 2009
    #1
    1. Advertising

  2. Marteno Rodia

    Albert Guest

    Marteno Rodia a écrit :
    > Hello everyone,
    > I'm building a GUI for an application and I want to display an image
    > as a part of a JFrame. Which component should I use for this purpose?
    > I thought I must implement my own component and overload its paint()
    > method, but I've found ImageIcon. Of course, first I need to read in
    > an image from a file to an Image object. It is possible to use
    > BufferedImage class and its read() method... But I must use an
    > uncompressed image in the PPM format (don't ask why, it's a
    > requitement). Apparently, the read() method won't recognize this
    > format. So what should I do?
    >
    > Unfortunately, I must implement reading the file by myself (it's not a
    > very complicated task). I think it's perhaps possible to "pull out"
    > the graphics context for the Image object and then to drow an image
    > pixel by pixel... But how to do it in detail?


    Well, with 2 for loops :

    BufferedImage bi = new BufferedImage(width, height, TYPE_INT_RGB);
    for (int i = 0; i < width; i++)
    for (int j = 0; j < height; j++)
    bi.setRGB(r, g, b);

    You try to set the pixel in the image while reading the file (best) or
    read all the data of the file in some arraylist, and after that setting
    the pixel in the image from the arraylist. If you don't know the
    direction of the pixel in the file, you should find the PPM specs (or
    try changing the loops until you succeded).
     
    Albert, Jun 23, 2009
    #2
    1. Advertising

  3. In article <4a40922b$0$12640$>,
    Albert <> wrote:

    > Marteno Rodia a écrit :
    > > Hello everyone,
    > > I'm building a GUI for an application and I want to display an
    > > image as a part of a JFrame. Which component should I use for this
    > > purpose? I thought I must implement my own component and overload
    > > its paint() method, but I've found ImageIcon. Of course, first I
    > > need to read in an image from a file to an Image object. It is
    > > possible to use BufferedImage class and its read() method... But I
    > > must use an uncompressed image in the PPM format (don't ask why,
    > > it's a requitement). Apparently, the read() method won't recognize
    > > this format. So what should I do?
    > >
    > > Unfortunately, I must implement reading the file by myself (it's
    > > not a very complicated task). I think it's perhaps possible to
    > > "pull out" the graphics context for the Image object and then to
    > > drow an image pixel by pixel... But how to do it in detail?

    >
    > Well, with 2 for loops :
    >
    > BufferedImage bi = new BufferedImage(width, height, TYPE_INT_RGB);
    > for (int i = 0; i < width; i++)
    > for (int j = 0; j < height; j++)
    > bi.setRGB(r, g, b);


    ITYM the method setRGB(int x, int y, int rgb) in BufferedImage:

    <http://java.sun.com/javase/6/docs/api/java/awt/image/BufferedImage.html>

    Also, it's sometimes convenient to modify the underlying raster, as
    shown here:

    <http://sites.google.com/site/drjohnbmatthews/raster>

    > You try to set the pixel in the image while reading the file (best)
    > or read all the data of the file in some arraylist, and after that
    > setting the pixel in the image from the arraylist. If you don't know
    > the direction of the pixel in the file, you should find the PPM specs
    > (or try changing the loops until you succeded).


    --
    John B. Matthews
    trashgod at gmail dot com
    <http://sites.google.com/site/drjohnbmatthews>
     
    John B. Matthews, Jun 23, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Varn
    Replies:
    2
    Views:
    375
    Ken Varn
    May 19, 2004
  2. Bob
    Replies:
    1
    Views:
    919
    Knute Johnson
    Nov 28, 2006
  3. Read pixels from a PGM/PPM Image

    , May 23, 2005, in forum: C Programming
    Replies:
    2
    Views:
    1,660
    Malcolm
    May 24, 2005
  4. Martin P. Hellwig
    Replies:
    2
    Views:
    1,227
    Martin P. Hellwig
    Dec 9, 2009
  5. Marko Faldix

    ppm: ppm install Spreadsheet::ParseExcel

    Marko Faldix, Jan 26, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    435
    James Willmore
    Jan 27, 2004
Loading...

Share This Page