0

I have the following Java ME code that I'd like to port to BlackBerry:

Image imgAll = Image.createImage("/fontDigits_200x20.png");
imageDigits = new Image[10];
for(int i = 0; i < imageDigits.length; i++)
    imageDigits[i] = Image.createImage(imgAll, i * 20, 0, 20, 20, Sprite.TRANS_NONE);

Basically, it's one image of ten digits that I want to split into 10 individual images and store them into an array. I looked through the docs, but can't find anything similar on EncodedImage or Graphics.

Thank you for any pointers!

UPDATE:

Good news! Apparently there's no way to crop an EncodedImage in such a way as to have a new EncodedImage which is a cropped subset of the original. However, you can do that with a Bitmap, which essentially is the same.

Community
  • 1
  • 1
Levon
  • 1,681
  • 2
  • 18
  • 40

2 Answers2

1

you can use

Bitmap.getARGB(int[] argbData,
                    int offset,
                    int scanLength,
                    int x,
                    int y,
                    int width,
                    int height)

after loading your image

Bitmap imgAll = Bitmap.getBitmapResource("fontDigits_200x20.png");

and off course you can create new Bitmap from this ARGB data.

Mahdi Hijazi
  • 4,424
  • 3
  • 24
  • 29
  • Yes, the bitmap gets created, however the transparency is not preserved -- it paints the transparent area with white pixels. The reason I'm using a .png image rather than a bitmap, is to preserve the transparency. Thank you, but unfortunately I can't use it. – Levon Sep 24 '10 at 18:59
0

You can do it directly with the Bitmap.scaleInto function:

Bitmap src;
Bitmap dst = new Bitmap(64,32);
int filterType = Bitmap.FILTER_BILINEAR;
src.scaleInto(srcLeft, srcTop, srcWidth, srcHeight, dst, dstLeft, dstTop, dstWidth, dstHeight, filterType);
Dave Dopson
  • 41,600
  • 19
  • 95
  • 85
  • Just a warning that scaleInto was introduced in 5.0, which may be fine depending on the app, but something to keep in mind – Anthony Rizk Sep 20 '10 at 02:10
  • I need this to work on 4.3 devices as well, but thank you for the tip, it will be useful in the future. – Levon Sep 23 '10 at 17:00
  • Thanks for the heads up about 5.0. I have ripped it out of my code and implemented a nice fixed-point bitmap scaler instead. – Dave Dopson Sep 25 '10 at 01:44