Reputation: 3623
I have large size of images i need to cut 60% height and 60% width and display the resulted image with rounded corner.
I have applied this code
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
Its working fine, but i have to set approx 50 images like this. So its slow down the process, and i have to wait 4 second approx to open the Activity for this whole process.
I also tried
android:adjustViewBounds="true"
but because of it my images are set but the problem is because large images will shrink in small area.its not looking good.
Do any one have any other way to do this job? Is it possible to do this whole job in xml so that on run time we can reduce some time in Activity opening.Please help..
Upvotes: 0
Views: 592
Reputation: 1311
These example are based on Image caching both memory caching as well as DiskLRU caching
Android-Universal-Image-Loader
Please read caching bitmaps thoroughly it will surely help you.
Upvotes: 1
Reputation: 2085
You need to do a lot of heavy computing on the handset. To achieve your goal I would recommend using Renderscript. A good place to start is http://developer.android.com/guide/topics/renderscript/compute.html
You could implement the heavy computing in a service to take off the load of the main thread. I'm not pretty sure how you do the display of the data but you could provide a default image for your placeholders and start updating them as the service goes doing the job. You can broadcast an intent to indicate the completion of every reduction of images.
You must also implement a cache for the "thumbnails" so you don't have to do all the computation every time the user starts your application.
Regards.
Upvotes: 0