1

Can anyone know the way how to use createEncodedImage method of EncodedImage class in jde 4.5

Thanks and regards, Vivek Birdi

skaffman
  • 398,947
  • 96
  • 818
  • 769
user291977
  • 237
  • 1
  • 5
  • 11

1 Answers1

1

Here's how you would do it if the Image was a resource file of the application:

byte[] imgData = null;
InputStream in = Application.getApplication().
        getClass().getResourceAsStream(imgName);
if(in == null) {
    // Handle appropriately
}

try {
    int length = in.available();
    imgData = new byte[length];
    in.read(bytes, 0, length);
} finally {
    in.close();
}

if(imgData == null) {
    // Handle appropriately
}

EncodedImage encodedImage = 
        EncodedImage.createEncodedImage(imgData, 0, imgData.length);

You could also pass a String as a parameter to define the MIME type. These are the supported MIME types:

  • "image/gif"
  • "image/png"
  • "image/vnd.wap.wbmp"
  • "image/jpeg" (supported only on Colour devices)
  • "image/jpg" (supported only on Colour devices)
  • "image/pjpeg" (supported only on Colour devices)
  • "image/bmp"
  • "image/tiff"

Finally, here's the documentation for 4.5: [EncodedImage Javadocs 4.5][1]

[1]: http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/system/EncodedImage.html#createEncodedImage(byte[], int, int)

Fostah
  • 11,398
  • 10
  • 46
  • 55
  • hi fostah, Thanks for your quick reply. But I am getting problem at line below: byte[] imageData = Resource.getResourceClass().getResource("res_img.gif"); compiler giving error that getResourceClass() is undefined for Resource. And I could not find documentation for Resource class in blackberry jde 4.5 API. Thanks and regards, Vivek Birdi. – user291977 Apr 30 '10 at 06:18
  • You're correct. I'llupdate how to accomplish what Resource.getResourceClass().getResource() does. Sorry about that. – Fostah May 03 '10 at 12:43
  • ok, But thanks a lot. I got the solution. InputStream input = this.getClass().getResourceAsStream("image.png"); EncodedImage encoded =null; try{ byte []b = new byte[input.available()]; input.read(b); encoded = EncodedImage.createEncodedImage(b, 0, b.length); }catch(Exception e){ System.out.println("Exceptin "+ e); } And image should be present in same package where we are writing the class or need some path to specify where we have located the image. – user291977 May 06 '10 at 07:16