JohnDoe4136
JohnDoe4136

Reputation: 539

Display image from SD card to phone - JavaME

I am trying to display an image from my SD card on my BlackBerry.

The code I have is this but nothing is showing on the BlackBerry screen.

InputStream input = filenames.openInputStream();
Image image=Image.createImage(input);
Image copy = Image.createImage(image.getWidth(), image.getHeight());            
javax.microedition.lcdui.Graphics g = copy.getGraphics();
g.drawImage(image, 0, 0, 0);

Upvotes: 0

Views: 494

Answers (1)

Greg McGowan
Greg McGowan

Reputation: 1360

I think the problem might be with the fact you are creating an Image copy and trying to draw the input image onto that. Without knowing the rest of your code, it then seems like this image is never added onto your MainScreen object so is not displayed.

Is there any particular reason you are trying to do it this way?

You might be better using a BitmapField instead and explictly adding it to your MainScreen. Something like

    BitmapField imageCanvas = new BitmapField();

    InputStream input = photoFile.openInputStream();

    int fileSize = (int) photoFile.fileSize();
    byte[] data = new byte[fileSize];
    input.read(data, 0, fileSize);

    Bitmap photoBitmap = EncodedImage.createEncodedImage(data, 0, data.length).getBitmap();
    imageCanvas.setBitmap(photoBitmap);
    add(imageCanvas);

I've left out the try catch blocks for brevity

Upvotes: 1

Related Questions