load and display image using CDC

Hi everyone,Please help. I'm new to java. I need a simple routine to load and display an image from the file system into a CDC app on windows mobile 5. I'm usin creme 4.1. Thanx in advance
[211 byte] By [ftubaila] at [2007-11-27 7:09:32]
# 1

Use the following as a guide:

1. Get the image (path below must be absolute):

public static Image getImage(String filename) throws ScanException {

Image img = null;

// Read paths from properties file

StringBuffer buf = new StringBuffer("\\");

buf.append(ScanUtility.getPathImages());

buf.append("\\");

buf.append(filename);

buf.append(".jpg");

File dataFile = new File(buf.toString());

if(!dataFile.exists())

throw new ScanException("Cannot locate the file:\n" + dataFile.getAbsolutePath());

img = Toolkit.getDefaultToolkit().createImage(buf.toString());

return img;

}

2. Create a class to display the image (pass in the image, above):

ImagePanel class source:

import java.awt.*;

import java.awt.image.*;

public class ImagePanel extends Panel {

private Image image = null;

private Image scaledImage = null;

private boolean imageComplete = false;

public ImagePanel(Image img) {

image = img;

scaledImage = image.getScaledInstance(200, -1, Image.SCALE_DEFAULT);

prepareImage(scaledImage, this);

}

// Override the paint method, to render the image

public void paint(Graphics g) {

if(imageComplete) {

g.drawImage(scaledImage, 0, 0, this);

}

}

// Override imageUpdate method, to prevent repaint() from trying

// to do anything until the image is scaled

public boolean imageUpdate(Image img, int infoFlags, int x, int y, int w, int h) {

if(infoFlags == ImageObserver.ALLBITS) {

imageComplete = true;

repaint();

}

return super.imageUpdate(img, infoFlags, x, y, w, h);

}

public void flush() {

image.flush();

scaledImage.flush();

image = null;

scaledImage = null;

}

}

joe.coma at 2007-7-12 19:00:55 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
Thank you very much for the reply. There is one problem, I don't know how to call the class. I put the first code on a button, and put the second code on a class, but I don't know how to call it. I'm new java. Please help.Best regards
ftubaila at 2007-7-12 19:00:55 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
Sorry, but I'm afraid I can't instruct you in how to program in Java (too much to cover in this type of medium).However, once you've learned enough to instantiate visual controls (panels, frames, and such), then the above-offered hints may help you.
joe.coma at 2007-7-12 19:00:55 > top of Java-index,Java Mobility Forums,Java ME Technologies...