hi i am pandian.
i have tried to display image in Jframe .
but it is only applicable for jpeg and png .
but i want to display image in bmp format.
i couldn't get it.
help me.
regards
mak.
Printable View
hi i am pandian.
i have tried to display image in Jframe .
but it is only applicable for jpeg and png .
but i want to display image in bmp format.
i couldn't get it.
help me.
regards
mak.
Let's see your attempt. What you should do is to write a very small compilable app that does nothing at all except try to show a BMP picture in the JFrame. Post it here with code tags and let's see what we can do to help you along. Oh, also are you using ImageIO to read in the BMP?
Here's my attempt:
Code:import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class ShowBMP
{
private static final String IMAGE_PATH =
"http://wvnvaxa.wvnet.edu/vmswww/images/test32v5.bmp";
private JPanel mainPanel = new JPanel()
{
@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
if (image != null)
{
g.drawImage(image, 0, 0, this);
}
}
};
Image image;
public ShowBMP()
{
try
{
image = ImageIO.read(new URL(IMAGE_PATH));
int width = image.getWidth(mainPanel);
int height = image.getHeight(mainPanel);
mainPanel.setPreferredSize(new Dimension(width, height));
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public JComponent getPanel()
{
return mainPanel;
}
private static void createAndShowGUI()
{
JFrame frame = new JFrame("ShowBMP Application");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new ShowBMP().getPanel());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args)
{
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
createAndShowGUI();
}
});
}
}