I want to show the Bitmap image in ImageView from sd card which is stored already. After run my application is crash and getting Ou
If android:largeHeap="true" didn't work for you then
1:
Image Compression. I am using this website
2:
Convert images to mdpi,hdpi, xhdpi, xxhdpi, xxxhdpi. I am using this webiste
Don't remove android:largeHeap="true"!
stream = activity.getContentResolver().openInputStream(uri);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.RGB_565;
bitmap = BitmapFactory.decodeStream(stream, null, options);
int Height = bitmap.getHeight();
int Width = bitmap.getWidth();
enter code here
int newHeight = 1000;
float scaleFactor = ((float) newHeight) / Height;
float newWidth = Width * scaleFactor;
float scaleWidth = scaleFactor;
float scaleHeight = scaleFactor;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
resizedBitmap= Bitmap.createBitmap(bitmap, 0, 0,Width, Height, matrix, true);
bitmap.recycle();
Then in Appliaction tag, add largeheapsize="true
have you tried adding this to your manifest under applications? android:largeHeap="true"
?
like this
<application
android:name=".ParaseApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:largeHeap="true" >
I had the problem too.
Same with most of others above. The problem is caused by huge image.
Just resize some images, and no need to change any code.
My problem solved after adding
dexOptions {
incremental true
javaMaxHeapSize "4g"
preDexLibraries true
dexInProcess = true
}
in Build.Gradle file
I ran into this problem when I didn't kill off my old activity when moving on to a new activity. I fixed it with finish();
Intent goToMain = new Intent(this,MainActivity.class);
startActivity(goToMain);
finish();