 |
Android - ImageLoader﹕ null java.lang.OutOfMemoryError แก้ยังไครับ LIB Android-Universal-Image-Loader |
|
 |
|
|
 |
 |
|
Error นี้เกิดจากขนาดของไฟล์ใหญ่เกินไปครับ 
|
 |
 |
 |
 |
Date :
2015-10-08 22:21:33 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ประมาณนั้นครับ
Code (Android-Java)
public static Bitmap decodeFile(File file, int iWidth, int iHeight){
try {
//Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(file),null,o);
//The new size we want to scale to
final int REQUIRED_WIDTH = iWidth;
final int REQUIRED_HIGHT = iHeight;
//Find the correct scale value. It should be the power of 2.
int scale=1;
while(o.outWidth/scale/2>=REQUIRED_WIDTH && o.outHeight/scale/2>=REQUIRED_HIGHT)
scale*=2;
//Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=scale;
return BitmapFactory.decodeStream(new FileInputStream(file), null, o2);
} catch (FileNotFoundException e) {}
return null;
}
Code (Android-Java)
Bitmap bm = decodeFile(new File("/sdcard/image.jpg"),200,200);
imgView.setImageBitmap(bm);
Android java.lang.OutOfMemoryError (แก้ปัญหาเรื่อง OutOfMemoryError ในการแสดงรูปภาพ)
|
 |
 |
 |
 |
Date :
2015-11-16 13:13:18 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กรณี Resize โดยใช้ Universal Image Loader
Code (Android-Java)
// *** Display Images
String imageUri = "https://www.thaicreate.com/mypicture/picture.jpg"; // URIs from HTTP Web
// Image Option
DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true)
.resetViewBeforeLoading(true)
.showImageForEmptyUri(R.drawable.ic_launcher)
.showImageOnFail(R.drawable.ic_launcher)
.showImageOnLoading(R.drawable.ic_launcher).build();
// Load image, decode it to Bitmap and return Bitmap synchronously
ImageSize targetSize = new ImageSize(80, 50); // result Bitmap will be fit to this size
Bitmap bmp = imageLoader.loadImageSync(imageUri, targetSize, options);
imageView.setImageBitmap(bmp);
Android and Universal Image Loader (Image Loader LIB:Library)
|
 |
 |
 |
 |
Date :
2015-11-24 08:39:44 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|