Share this page 

Display a BMP image (this howto is deprecated)Tag(s): DEPRECATED


The standard Java Image object doesn't support the BMP format (only JPG or GIF). While it's possible to use pure Java classes to let an Image use a BMP-encoded image (see this How-to), in a Microsoft-oriented environment, it's easier to use the WFC control PictureBox which can display BMP/, GIF or JPEG images.

In VJ++, create a Windows application. In the Java form, drag the WFC picturebox control and a button. In the button click event, put the following to call the Win FileOpen dialog to let you select the image to be displayed.

OpenFileDialog ofd = new OpenFileDialog();
  ofd.setDefaultExt("bmp");
  ofd.setFilter("BMP images(*.bmp)|*.bmp|JPG images (*.jpg)|*.jpg");
  ofd.setFilterIndex(1);
  ofd.setInitialDir("c:\\");
  int dlgResult = ofd.showDialog();
  if (dlgResult == DialogResult.OK) {
    pictureBox1.setImage(new Bitmap(ofd.getFileName()));
}

mail_outline
Send comment, question or suggestion to howto@rgagnon.com