I am trying to show SD Card image into ImageView and getting OutOfMemory error.
Please let me know How can i show SDCard's images into ImageView (no matter how big they are.)
I know we can use, these properties to control on it, but i am looking for the best solution :
android:hardwareAccelerated="false"
android:largeHeap="true"
Logcat:
08-05 11:27:34.530: E/AndroidRuntime(8158): FATAL EXCEPTION: main
08-05 11:27:34.530: E/AndroidRuntime(8158): java.lang.OutOfMemoryError
08-05 11:27:34.530: E/AndroidRuntime(8158): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
08-05 11:27:34.530: E/AndroidRuntime(8158): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:650)
08-05 11:27:34.530: E/AndroidRuntime(8158): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:389)
08-05 11:27:34.530: E/AndroidRuntime(8158): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:449)
08-05 11:27:34.530: E/AndroidRuntime(8158): at com.physic.UploadActivity.previewMedia(UploadActivity.java:171)
08-05 11:27:34.530: E/AndroidRuntime(8158): at com.physic.UploadActivity.onCreate(UploadActivity.java:109)
08-05 11:27:34.530: E/AndroidRuntime(8158): at android.app.Activity.performCreate(Activity.java:5191)
08-05 11:27:34.530: E/AndroidRuntime(8158): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
08-05 11:27:34.530: E/AndroidRuntime(8158): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
08-05 11:27:34.530: E/AndroidRuntime(8158): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
08-05 11:27:34.530: E/AndroidRuntime(8158): at android.app.ActivityThread.access$700(ActivityThread.java:140)
08-05 11:27:34.530: E/AndroidRuntime(8158): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
08-05 11:27:34.530: E/AndroidRuntime(8158): at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 11:27:34.530: E/AndroidRuntime(8158): at android.os.Looper.loop(Looper.java:137)
08-05 11:27:34.530: E/AndroidRuntime(8158): at android.app.ActivityThread.main(ActivityThread.java:4921)
08-05 11:27:34.530: E/AndroidRuntime(8158): at java.lang.reflect.Method.invokeNative(Native Method)
08-05 11:27:34.530: E/AndroidRuntime(8158): at java.lang.reflect.Method.invoke(Method.java:511)
08-05 11:27:34.530: E/AndroidRuntime(8158): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1036)
08-05 11:27:34.530: E/AndroidRuntime(8158): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:803)
08-05 11:27:34.530: E/AndroidRuntime(8158): at dalvik.system.NativeStart.main(Native Method)
Code:
/**
* Displaying captured image/video on the screen
* */
private void previewMedia(boolean isImage) {
// Checking whether captured media is image or video
if (isImage) {
imgPreview.setVisibility(View.VISIBLE);
final Bitmap bitmap = BitmapFactory.decodeFile(filePath);
ExifInterface exif = null;
try {
exif = new ExifInterface(filePath);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_UNDEFINED);
Bitmap bmRotated = rotateBitmap(bitmap, orientation);
imgPreview.setImageBitmap(bmRotated);
} else {
imgPreview.setVisibility(View.GONE);
}
}
Using Picasso Lib:
Picasso.with(UploadActivity.this)
.load(new File(filePath)).rotate(90)
.fit().centerInside()
.error(R.drawable.ic_launcher)
.placeholder(R.drawable.ic_launcher)
.into(imgPreview);
And even tried with this:
.transform(transformation)
Log:
Log.d("file:", filePath);
D/file:(6201): /storage/sdcard0/Pictures/Testing/LICPolicy20150805120029.jpg
Tried with Picasso lib but not showing image preview ..