简体   繁体   中英

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?

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.

我也不是完全熟悉BB,但是由于没有其他人在回答您的问题,因此请检查EncodedImage类,然后方法scaleImage32()应该返回缩放后的版本。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM