0

I currently use code like this that works at refitting the bitmaps for different screen sizes:

A.back = GPATools.ResizeTransparentBitmap(A.back, 150, 37,
                    Bitmap.FILTER_LANCZOS, Bitmap.SCALE_TO_FIT);

However, every time I load the app, it takes the time to resize it again, so I've been told to use this code for that:

class PersistableBitmap implements Persistable {

    int width;
    int height;
    int[] argbData;

    public PersistableBitmap(Bitmap image){
        width = image.getWidth();
        height = image.getHeight();
        argbData =new int[width * height];
        image.getARGB(argbData,0, width,0,0, width, height);
    }

    public Bitmap getBitmapImage(){
        Bitmap image =new Bitmap(width, height);
        image.setARGB(argbData,0, width,0,0, width, height);
        return image;
    }

My problem is, I have no idea how to implement the two together! Please help guys/gals, thanks a lot!

HulkingUnicorn
  • 599
  • 5
  • 9
Joey John John
  • 243
  • 2
  • 11
  • Add a few whitespaces to the snippet at least! – Mister Smith May 03 '12 at 16:11
  • I assume your bitmap is really big and that you have made the pertinent tests to prove that the resizing consumes more time than loading it from persistence. If not, I'd suggest you to include the pre-scaled image in project resources, or even caching the bitmap in the runtime store instead. – Mister Smith May 03 '12 at 16:17
  • white spaces? Anyway, I have a lot of images, they aren't big, but its just a large quantity. Someone also suggested that it might be blocking the main ui and to put it in another thread but I'm not exactly sure how to do that. – Joey John John May 03 '12 at 16:26
  • Change `classPersistableBitmapimplementsPersistable` to `class PersistableBitmap implements Persistable`, and fix other issues. – Rupak May 03 '12 at 18:08
  • that was just a copy and paste error Rupak. I'm wondering how to implement the two different codings – Joey John John May 03 '12 at 18:17

1 Answers1

1

Following links may be helpful:

Community
  • 1
  • 1
Rupak
  • 3,674
  • 15
  • 23
  • I already know how to use persistent store for regular data, its storing Bitmaps is my current problem. Thanks anyways. – Joey John John May 03 '12 at 18:30
  • 3
    An instance of `Bitmap` is just a combination of `regular data`, i.e. primitive data types. You said that you already know how to use persistent store for regular data, then what is the problem with the class `PersistableBitmap`? You just need to store only `width`, `height`, and `argbData` of the class `PersistableBitmap`. And when you finished reading that object from persistence store, you can use `getBitmapImage()` to get the `Bitmap`. If you have any confusion, then any one of the above link can help you. – Rupak May 03 '12 at 19:03