Pictures taken from the network, is to enlarge the size of 1024 * 768, requiring slide show, how do not OOM?
Daniel have any good suggestions?
Reply:
Displays thumbnails of it, so much the figure oh eat memory.
Reply:
Thumbnail can be used, but can not shrink too much, I am now reduced in general, is decodeStream when setting options for inSampleSize is at least 2, if the screen is 320 * 480 when he was 3, but the simulator still appeared OOM. . .
Reply:
Judgment sliding events, the picture is not loaded sliding
Timely recovery
Can only be the case. .
Reply:
Only this
Reply:
I'm here to listen to opinions.
Reply:
In fact, nothing Takami, then the large size of the picture, to look at the resolution memory size, you can consider the final device in 2GB or RAM 4GB, a picture memory usage for the resolution of the length x width x4 calculation, you understand. Recycling JVM memory management with weak references allow it.
Reply:
Hey. . For a long time did not come forums.
This problem. Is actually very simple.
3 steps
1: soft references. Consumption, and I say this with basically nothing. Is to prevent hang up, still can not see the picture.
2: I still put the code.
public static Bitmap loadImageFromUrl (String url, int sc) {
URL m;
InputStream i = null;
BufferedInputStream bis = null;
ByteArrayOutputStream out = null;
byte isBuffer [] = new byte [1024];
if (url == null)
return null;
try {
m = new URL (url);
i = (InputStream) m.getContent ();
bis = new BufferedInputStream (i, 1024 * 4);
out = new ByteArrayOutputStream ();
int len = 0;
while ((len = bis.read (isBuffer))! = -1) {
out.write (isBuffer, 0, len);
}
out.close ();
bis.close ();
} Catch (MalformedURLException e1) {
e1.printStackTrace ();
return null;
} Catch (IOException e) {
e.printStackTrace ();
}
if (out == null)
return null;
byte [] data = out.toByteArray ();
BitmapFactory.Options options = new BitmapFactory.Options ();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray (data, 0, data.length, options);
options.inJustDecodeBounds = false;
int be = (int) (options.outHeight / (float) sc);
if (be <= 0) {
be = 1;
} Else if (be> 3) {
be = 3;
}
options.inSampleSize = be;
Bitmap bmp = null;
try {
bmp = BitmapFactory.decodeByteArray (data, 0, data.length, options); / / Return to the thumbnail
} Catch (OutOfMemoryError e) {
/ / TODO: handle exception
System.gc ();
bmp = null;
}
return bmp;
}
3 Set the memory space
violenceprivate final static float TARGET_HEAP_UTILIZATION = 0.75f;
private final static int CWJ_HEAP_SIZE = 16 * 1024 * 1024;
VMRuntime.getRuntime ()
. SetTargetHeapUtilization (TARGET_HEAP_UTILIZATION);
VMRuntime.getRuntime () setMinimumHeapSize (CWJ_HEAP_SIZE);.
Reply:
The good, copying collection.
First, the soft references. Also has been used before, it should be in the memory of the time is jvm mandatory recycling is not it. Obviously there are a lot of memory later discovered, is far from the memory situation, bitmap or be recycled, look after a blogger said after Android 2.2, soft and weak references, as long as there is no gc got. So nothing really feeling the effect, often slippery slide forward and went with the network load images
The second point, the core is compressed images, reducing the quality of the picture. Finally the try catch is to force ah, ha ha
The third point, have not tried, do not know what consequences there! !
Reply:
The brother said good
Reply:
Can consider, downloaded to the local file system cache to make the case. Just need to periodically clean the disk.
Reply:
I feel even downloaded to the local time will be loaded as OOM error ah? This I still do not know how to solve, I have encountered this problem. My pictures even less, only a dozen copies. But once all the procedures needed to generate bitmap, then there mistake. I have not run out of a recycled one method. But do not know why there is an error in the simulator above, on my cell phone with no errors. android points are not all 8M of memory? Do not understand.
Reply:
Page loading, first load the interface can display maps, browse the timely recovery of the picture is no longer displayed, only be the case, there is no good way to go.
Reply:
Reply:
Reply:
"Guaranteed" can only be used in still life more suitable, Android Compatibility is a large problem.
Reply:
I am sorry to be late to find a job knot stickers, thank large cattle way! !
Reply:
Seeking skia.os, compiler pass Yeah, seeking Great God blessing. . . .
Reply:
Landlord not solve the problem ah?
Reply:
Have encountered such a problem. Changed the next. Still being tested
Reply:
http://blog.csdn.net/liliang497/article/details/7305257
No comments:
Post a Comment