Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
Posts: 144
Registered: ‎12-20-2008

Encoded image resizing

i found the code but same does not work it does nothing images set as original width height

 byte[] dataArray = data.getBytes();
                    bitmap = EncodedImage.createEncodedImage(dataArray, 0,
                                 dataArray.length); 
                   System.err.println( bitmap.getLength()+" "+bitmap.getWidth());
                   bitmap = resizeImage( bitmap, 150,150);
                  System.err.println( bitmap.getLength()+" "+bitmap.getWidth());
                                  setImage(bitmap);

 

private static EncodedImage resizeImage(EncodedImage image, int width, int height) {
    if (image == null) {
      return image;
    }

    //return if image does not need a resizing
    if (image.getWidth() <= width && image.getHeight() <= height) {
      return image;
    }
   
    double scaleHeight, scaleWidth;
    if (image.getWidth() > width && image.getHeight() > height) {  //actual image is bigger than scale size
      if (image.getWidth() > image.getHeight()) {  //actual image width is more that height then scale with width
        scaleWidth = width;
        scaleHeight = (double)width / image.getWidth() * image.getHeight();
      } else { //scale with height
        scaleHeight = height;
        scaleWidth = (double)height / image.getHeight() * image.getWidth();
      }
    } else if (width < image.getWidth()) { //scale with scale width or height
      scaleWidth = width;
      scaleHeight = (double)width / image.getWidth() * image.getHeight();
    } else {
      scaleHeight = height;
      scaleWidth = (double)height / image.getHeight() * image.getWidth();
    }
    int w = Fixed32.div(Fixed32.toFP(image.getWidth()), Fixed32.toFP((int)scaleWidth));
    int h = Fixed32.div(Fixed32.toFP(image.getHeight()), Fixed32.toFP((int)scaleHeight));
    return image.scaleImage32(w, h);
  }
tks in advance 
r.soler

 

 

Please use plain text.
Administrator
MSohm
Posts: 12,957
Registered: ‎07-09-2008
My Carrier: Bell

Re: Encoded image resizing

I haven't tried your code, but I know this one does work.

 

http://supportforums.blackberry.com/t5/Java-Development/Resizing-a-Bitmap-using-scaleImage32-instead...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Please use plain text.
New Contributor
sanjeewa190
Posts: 6
Registered: ‎12-03-2010

Re: Encoded image resizing

Please use plain text.
Developer
rcmaniac25
Posts: 1,789
Registered: ‎04-28-2009
My Carrier: Verizon

Re: Encoded image resizing

?

 

@sanjeewa190: I don't believe that has anything to do with this post.

------------------------------------------------------------
Three simple rules:
1. Please use the search bar before making new posts.
2. Kudo posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.

Projects:
Bing 4 BlackBerry: http://bbing.codeplex.com/
PDF Renderer 4 BlackBerry: http://pdfrend4bb.codeplex.com/
Please use plain text.
New Contributor
sanjeewa190
Posts: 6
Registered: ‎12-03-2010

Re: Encoded image resizing

http://sanjeewamalalgoda.blogspot.com/2010/12/zooming-bitmap-images-in-blackberry.html

This post shows resizing image to given factor and later post about encoded image

Please use plain text.