How can I scale down an image to half the size using scaleImage32 ()?

Now I have:

    EncodedImage logo = EncodedImage.getEncodedImageResource("image.png");
    logo.scaleImage32(Fixed32.toFP(2), Fixed32.toFP(2));
    BitmapField image = new BitmapField(logo.getBitmap());
    image.setMargin(15, 15, 15, 15);
    this.add(image);

      

and it just displays the image at its normal size. However logo.setScale(2)

works instead .scaleImage32(...)

, but it's deprecated.

What is the correct way to use .scaleImage32 () to display my image at half its size?

+3


source to share


1 answer


Unfortunately you had snooker with the crummy API and, in my opinion, a weakness in Java (and all C languages).

You thought you were scaleImage32()

scaling your image logo

. This is not true. It returned a copy logo

that was scaled. You, however, did nothing with this value. You used logo

to display in your bitmap field when you really need a scaled copy returned by scaleImage32()

:

EncodedImage logo = EncodedImage.getEncodedImageResource("image.png");
EncodedImage scaledLogo = logo.scaleImage32(Fixed32.toFP(2), Fixed32.toFP(2));
BitmapField image = new BitmapField(scaledLogo.getBitmap());

      

I'll add a few things:



1) if you can restrict your app to OS 5.0 and up I find the scaleInto () API is easier to use

2) This kind of scenario is why people pop in method names. RIM chose a bad name for scaleImage32()

, as it leads you to believe that the instance you are calling the method on will scale. It should be named getScaledImage32()

or something like that.

3) under the heading of obscure programming stuff that I'm confused to admit I used Ada code . Ada was committed to preventing programming errors as much as possible. One of the features of Ada was that the compiler treats an unused return value as an error. This scenario is precisely why.

So, don't feel too bad about it :)

+3


source







All Articles