Create Image from PNG image : PNG « J2ME « Java Tutorial






import java.io.IOException;

import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.midlet.MIDlet;

public class ImageCreateImage extends MIDlet {
  protected Display display;

  protected void startApp() {
    display = Display.getDisplay(this);

    Form form = new Form("Demo");

    form.append("line");
    try {
      Image red = Image.createImage("/red.png");
      form.append(new ImageItem(null, red, ImageItem.LAYOUT_DEFAULT, null)); 

    } catch (IOException ex) {
      form.append("Failed to load images");
    }
    display.setCurrent(form);
  }

  protected void pauseApp() {
  }

  protected void destroyApp(boolean unconditional) {
  }
}








31.36.PNG
31.36.1.Create Image from PNG image