This is not a duplicate of Mysterious stacktrace in Android developer console (bitmap size exceeds 32bits)
That question didn't provide a single line of code and there's no answer either; besides, I get this error even if I set the Bitmap size to 32x32, it is the only Bitmap, so it is not memory related.
What I want to do
- Get the size of an ImageView,
- create a BitMap
- and draw something on a Canvas.
The Log.e
output for the size of the ImageView and therefore Bitmap is:
Width: 272
Height: 136
What happens
The below code works well on Nexus4, Nexus7 and Desire HD (CM10), but running the app on the emulator gives me the error shown below (API 8).
Findings
I've tried it with half the size and 32x32, which gives the same error.
I am displaying the ImageView in a DialogFragment (ActionBarSherlock/HoloEveryWhere for API 8), maybe that's the culprit?
ImageView:
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="12dp"
android:layout_marginTop="12dp" />
In my activity:
iv = (ImageView) view.findViewById(R.id.imageView1);
ViewTreeObserver vto = iv.getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
if (!waveFormMeasured) {
if (iv.getMeasuredWidth() > 1) {
width = iv.getMeasuredWidth();
Log.e(TAG, "Width: " + width + " Height: " + width / 2);
waveBitmap = Bitmap.createBitmap((int) width, (int) ((int) width / 2), Config.RGB_565);
Log.e(TAG, "Bitmap created");
waveCanvas = new Canvas(waveBitmap);
Log.e(TAG, "Bitmap set to Canvas");
iv.getLayoutParams().height = width / 2;
Log.e(TAG, "ImageView Height changed");
iv.setImageBitmap(waveBitmap);
Log.e(TAG, "Bitmap set to ImageView");
drawWaveForm(true);
Log.e(TAG, "WaveForm drawn");
waveFormMeasured = true;
}
}
return true;
}
});
What is wrong here ?
02-21 17:12:48.301: E/Drummers(375): Width: 272 Height: 136
02-21 17:12:48.301: E/Drummers(375): Bitmap created
02-21 17:12:48.301: E/Drummers(375): Bitmap set to Canvas
02-21 17:12:48.301: E/Drummers(375): ImageView Height changed
02-21 17:12:48.301: E/Drummers(375): Bitmap set to ImageView
02-21 17:12:48.623: E/Drummers(375): WaveForm drawn
02-21 17:12:48.842: E/AndroidRuntime(375): FATAL EXCEPTION: main
02-21 17:12:48.842: E/AndroidRuntime(375): java.lang.IllegalArgumentException: bitmap size exceeds 32bits
02-21 17:12:48.842: E/AndroidRuntime(375): at android.graphics.Bitmap.nativeCreate(Native Method)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.View.buildDrawingCache(View.java:6577)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.ViewGroup.onAnimationStart(ViewGroup.java:1259)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.ViewGroup.drawChild(ViewGroup.java:1505)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.View.draw(View.java:6883)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.View.draw(View.java:6986)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.widget.FrameLayout.draw(FrameLayout.java:357)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.widget.ScrollView.draw(ScrollView.java:1409)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.View.buildDrawingCache(View.java:6640)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.ViewGroup.onAnimationStart(ViewGroup.java:1259)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.ViewGroup.drawChild(ViewGroup.java:1505)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.View.draw(View.java:6883)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.widget.FrameLayout.draw(FrameLayout.java:357)
02-21 17:12:48.842: E/AndroidRuntime(375): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1862)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.ViewRoot.draw(ViewRoot.java:1522)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.ViewRoot.performTraversals(ViewRoot.java:1258)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.os.Handler.dispatchMessage(Handler.java:99)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.os.Looper.loop(Looper.java:123)
02-21 17:12:48.842: E/AndroidRuntime(375): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-21 17:12:48.842: E/AndroidRuntime(375): at java.lang.reflect.Method.invokeNative(Native Method)
02-21 17:12:48.842: E/AndroidRuntime(375): at java.lang.reflect.Method.invoke(Method.java:507)
02-21 17:12:48.842: E/AndroidRuntime(375): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-21 17:12:48.842: E/AndroidRuntime(375): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-21 17:12:48.842: E/AndroidRuntime(375): at dalvik.system.NativeStart.main(Native Method)