0

我正在使用下面的代码来调整黑莓中的图像大小,但这会导致图像质量不佳。请提供相同的建议。

         {
      JPEGEncodedImage encoder = null;
      encode_image = sizeImage(encode_image, (int)newWidth,(int)newHeight);
      encoder=JPEGEncodedImage.encode(encode_image.getBitmap(),100);
        }

     public EncodedImage sizeImage(EncodedImage image, int width, 
          int height) {
          EncodedImage result = null;



          int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
          int currentHeightFixed32 = Fixed32.toFP(image.getHeight());

          int requiredWidthFixed32 = Fixed32.toFP(width);
          int requiredHeightFixed32 = Fixed32.toFP(height);

          int scaleXFixed32 = Fixed32.div(currentWidthFixed32,
            requiredWidthFixed32);
          int scaleYFixed32 = Fixed32.div(currentHeightFixed32,
            requiredHeightFixed32);

          result = image.scaleImage32(scaleXFixed32, scaleYFixed32);
                    return result;
         }
4

2 回答 2

1

黑莓的默认图像缩放非常原始,通常看起来不太好。如果您正在为 5.0 构建,则有一个新的 API可以使用双线性或 Lanczos 等过滤器进行更好的图像缩放。

于 2010-05-20T16:31:07.927 回答
0

您可能已经解决了您的问题,但是对于需要编写与旧 API 兼容的代码的其他编码人员,您也可以使用这篇文章中的代码:将图像加载到 Bitmap 对象时出现奇怪的内存不足问题

该线程是关于 android 的,但图像缩放数学和逻辑是相同的 :)

于 2011-01-17T12:40:35.097 回答