0

I have a problem in my android application. I use an application which make pictures with the build in camera of a phone/tablet.These pictures are sometimes quite large in size because of the high resolution of the camera.

Now i load the application and create a listView, where a small thumbnail of the picture is on the left side and on the right is some text.

I create the pictures in this way:

Bitmap a = BitmapFactory.decodeFile(url);
int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 
         (float) 66.0, context.getResources().getDisplayMetrics());
int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 
         (float) 48.0, context.getResources().getDisplayMetrics());
Bitmap b = Bitmap.createScaledBitmap(a, width, height, false);

The problem is that this step take quite a long time.

Is there any way to make this faster?

gurehbgui
  • 14,236
  • 32
  • 106
  • 178

2 Answers2

0

There is no way to make it faster, but you should not block the UI thread. See

  1. AsyncTask (and many related questions like Using AsyncTask to load Images in ListView)
  2. LruCache
Community
  • 1
  • 1
rds
  • 26,253
  • 19
  • 107
  • 134
0

This is the solution I used taken from here: https://stackoverflow.com/a/5934983/1369222

It works great!

byte[] imageData = null;

        try     
        {

            final int THUMBNAIL_SIZE = 64;

            FileInputStream fis = new FileInputStream(fileName);
            Bitmap imageBitmap = BitmapFactory.decodeStream(fis);

            imageBitmap = Bitmap.createScaledBitmap(imageBitmap, THUMBNAIL_SIZE, THUMBNAIL_SIZE, false);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();  
            imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
            imageData = baos.toByteArray();

        }
        catch(Exception ex) {

        }

Make sure you do this in an Async or a separate thread task so you don't block up the UI thread!

Community
  • 1
  • 1
Anup Cowkur
  • 20,443
  • 6
  • 51
  • 84