Solved

How to display a "PGM" image file in java?

Posted on 2002-07-17
2
1,981 Views
Last Modified: 2008-01-09
How I can display a "PGM" (Portable Gray Map) file in java? Please write some actual code.

regards,
Subhasis
0
Comment
Question by:mitra_subhasis
2 Comments
 
LVL 2

Accepted Solution

by:
flumpman earned 50 total points
ID: 7161689
Using the JAI the code is simple - see below.

--
flumpman

import javax.media.jai.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class DisplayPGM {

    public static void main(String[] args) {

        JFrame f = new JFrame("PGM");

        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        // create a JPanel to use as the content pane
        JPanel p = new JPanel();
        p.setLayout(new BorderLayout());

        f.setContentPane(p);

        // load the image using JAI
        PlanarImage pgmImage = JAI.create("fileload", "c:\\temp\\test.pgm");

        // create an ImageIcon from the image
        ImageIcon icon = new ImageIcon(pgmImage.getAsBufferedImage());

        JLabel l = new JLabel(icon);

        // add the image to the panel
        p.add(l, BorderLayout.CENTER);

        // set the size and show the frame
        f.setSize(600, 400);
        f.setVisible(true);
    }
}
0
 

Author Comment

by:mitra_subhasis
ID: 7171006
Sorry for being late.

regards,
Subhasis.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 84
How to monitor the number of connections/threads being utilized on Tomcat 6.0 8 70
factorial example 4 39
spring jars download 1 26
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

805 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question