开发者

Display image from SD card to phone - JavaME

开发者 https://www.devze.com 2023-02-14 11:06 出处:网络
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 Bl开发者_StackOverflow社区ackBerry screen.

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 Bl开发者_StackOverflow社区ackBerry 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);


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

0

精彩评论

暂无评论...
验证码 换一张
取 消