在 BlackBerry 上显示缩放图像

发布于 2024-10-07 13:51:04 字数 70 浏览 0 评论 0原文

我的 BlackBerry 应用程序应从 Web 服务获取图像并将该图像显示为缩略图。谁能给我一个关于如何实现这一目标的想法?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

居里长安 2024-10-14 13:51:04

petteri关于使用EncodedImage和scaleImage32()的说法是正确的。具体来说,您需要将 createEncodedImage(byte[] data, int offset, int length) 与 Web 服务返回的字节一起使用。

请注意,scaleImage32 采用“int”参数,但它们是定点数,与更广为人知的浮点数不同。要获取所需的定点值,请使用 Fixed32

最后,如果您不需要 BlackBerry 应用程序中的原始图像,如果 Web 服务进行缩放,您将获得更好的整体体验。这将减少传输到设备的字节数,并且减少设备上缩放图像所需的计算量。服务器上的缩放也可能会产生更高质量的缩放图像,因为scaleImage32() 使用相当基本的算法。

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.

左耳近心 2024-10-14 13:51:04

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

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.

冧九 2024-10-14 13:51:04

此代码可以帮助您

        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();

这将从您的 Web 服务 url 生成字节数组。这里 bb 是字节数组。

BB 中有两个处理图像的类。 EncodedImageBitmap 都有从字节数组生成图像的构造函数。我建议使用位图,它具有轻松调整图像大小的功能。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文