I have ViewPager which I use to show zoomable images (using ImageViewTouch). I need to load large bitmaps from Internet (http). By large I mean 2000x1000. The images need to be so large, because they are zoomable and need to show details. Images on server are .jpg format, but it's not problem - I can change it.
How can I manage to load so large images to ImageViewTouch (ImageView) without getting probles with memory?
By now I'm using simply this (AsyncTask):
ImageView currentView; //ImageView where to place image loaded from Internet
String ImageUrl; //URL of image to load
protected Bitmap doInBackground(ArrayList... params) {
Bitmap bitmap;
InputStream in = null;
imageUrl = (String)params[0].get(1);
try{
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(imageUrl));
in = response.getEntity().getContent();
} catch(Exception e){
e.printStackTrace();
}
try {
bitmapa = BitmapFactory.decodeStream(in);
in.close();
} catch (IOException e1) {
e1.printStackTrace();
}
return bitmap;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
currentView.setImageBitmap(bitmap);
}
And it cause many problems with memory:
E/dalvikvm-heap(369): 69560740-byte external allocation too large for this process.
E/GraphicsJNI(369): VM won't let us allocate 69560740 bytes
or
E/AndroidRuntime(369): java.lang.RuntimeException: An error occured while executing doInBackground()
E/AndroidRuntime(369): at android.os.AsyncTask$3.done(AsyncTask.java:200)
E/AndroidRuntime(369): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
E/AndroidRuntime(369): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
E/AndroidRuntime(369): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
E/AndroidRuntime(369): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
E/AndroidRuntime(369): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
E/AndroidRuntime(369): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
E/AndroidRuntime(369): at java.lang.Thread.run(Thread.java:1019)
E/AndroidRuntime(369): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
E/AndroidRuntime(369): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
E/AndroidRuntime(369): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:470)
E/AndroidRuntime(369): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:525)
E/AndroidRuntime(369): at com.package.app.ImageDownloader.doInBackground(ImageDownloader.java:78)
E/AndroidRuntime(369): at com.package.app.ImageDownloader.doInBackground(ImageDownloader.java:1)
E/AndroidRuntime(369): at android.os.AsyncTask$2.call(AsyncTask.java:185)
E/AndroidRuntime(369): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
E/AndroidRuntime(369): ... 4 more