0

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;
         }
Maneesh
  • 6,098
  • 5
  • 36
  • 55

2 Answers2

1

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
  • 44,628
  • 11
  • 58
  • 63
0

You've probably already fixed your issue, but for other coders that need to write code that's compatible with the older API's you can also use the code from this post: Strange out of memory issue while loading an image to a Bitmap object

The thread is about android, but the image scaling math and logics are the same :)

Community
  • 1
  • 1
Thomas Vervest
  • 2,131
  • 1
  • 16
  • 13