Unfortunately, you've been snookered by a crummy API, and in my opinion, a weakness of Java (and all the C languages).
You thought that scaleImage32()
was scaling your logo
image. It wasn't. It was returning a copy of logo
that was scaled. You, however, didn't do anything with this value. You used logo
for display in your bitmap field, when you really needed the scaled copy that scaleImage32()
returns:
EncodedImage logo = EncodedImage.getEncodedImageResource("image.png");
EncodedImage scaledLogo = logo.scaleImage32(Fixed32.toFP(2), Fixed32.toFP(2));
BitmapField image = new BitmapField(scaledLogo.getBitmap());
I will add a few things:
1) if you can restrict your app to OS 5.0 and above, I think that the scaleInto() API is easier to use
2) this kind of scenario is why people fuss over method names. RIM picked a poor name for scaleImage32()
, as that leads you to believe that the instance on which you call the method will be scaled. It should have been named getScaledImage32()
, or something like that.
3) under the heading of obscure programming stuff that I'm embarrased to admit, I used to code in Ada. Ada was geared towards doing as much as possible to prevent programming errors. One thing Ada featured was that the compiler treats an unused return value as an error. This scenario is exactly why.
So, don't feel too bad about this one :)