views:

99

answers:

1

I am using below code to resize image in blackberry but it resulting into poor quality of image. Please advise on the same.

         {
      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;
         }
+1  A: 

The default image scaling done by BlackBerry is quite primitive and generally doesn't look very good. If you are building for 5.0 there is a new API to do much better image scaling using filters such as bilinear or Lanczos.

Marc Novakowski