user469999
user469999

Reputation: 2171

Display scaled image on BlackBerry

My BlackBerry application should fetch an image from a web service and display the image as a thumbnail. Can anyone give me an idea on how to achieve this?

Upvotes: 1

Views: 375

Answers (3)

Michael Donohue
Michael Donohue

Reputation: 11876

petteri is right about using EncodedImage and scaleImage32(). Specifically, you'll want to use createEncodedImage(byte[] data, int offset, int length) with the bytes returned by the webservice.

Be aware that scaleImage32 takes 'int' arguments, but they are fixed-point numbers, in contrast to the more widely known floating-point numbers. To get the fixed-point value you want, use the utility methods in Fixed32

Finally, if you don't need the original image in the BlackBerry application, you will have a better overall experience if the webservice does the scaling. This will reduce the number of bytes transferred to the device, and it will reduce the computation done on device to scale the image. Scaling on the server will likely result in a higher quality scaled image as well, as scaleImage32() uses a fairly basic algorithm.

Upvotes: 5

Prasham
Prasham

Reputation: 6686

This code can help you

        connection = (HttpConnection) Connector.open(fullUrl.toString(),
            Connector.READ_WRITE, true);


        InputStream is = hc.openInputStream();

        DataInputStream dis = new DataInputStream(is);
        ByteArrayOutputStream bStrm = new ByteArrayOutputStream();

        int ch;
        while ((ch = dis.read()) != -1) {
            // System.out.println((char) ch);
            // msg = msg + (char) ch;
            bStrm.write(ch);
        }
        bb = bStrm.toByteArray();

This will generate Byte Array from your web service url. here bb is byte array.

There are two classes that handles image in BB. EncodedImage and Bitmap, both have constructors that generate image from byte array. I recommend use Bitmap, it has easy image re size capability.

Upvotes: 1

petteri
petteri

Reputation: 354

I'm not totally familiar with BB either but since nobody else is answering your question, check out EncodedImage class and there method scaleImage32() should return you the scaled version.

Upvotes: 3

Related Questions