Android Studio canvas: drawing a bitmap too large

I am using Ubuntu 16.04. And in Android Studio, when I try to run my application in the emulator, I get the following error:

EXCLUSIVE EXCLUSION: main process: here is the name of the project, PID: 2528 java.lang.RuntimeException: Canvas: attempt to draw a too large (216090000 bytes) bitmap. on android.view.DisplayListCanvas.throwIfCannotDraw (DisplayListCanvas.java:260) on android.graphics.Canvas.drawBitmap (Canvas.java:1415) on android.graphics.drawable.BitmapDrawable.draw (BitmapDrawable.javahaps28) ​​on android. widget.ImageView.onDraw (ImageView.java:1316) on android.view.View.draw (View.java:17185) on android.view.View.updateDisplayListIfDirty (View.java:16167) on android.view.View.draw (View.java:16951) in android.view.ViewGroup.drawChild (ViewGroup.java:3727) in android.view.ViewGroup.dispatchDraw (ViewGroup.java:3513) in android.view.View.updateDisplayListIfDirty (View.java: 16162) in android.view.View.draw (View.java:16951) in android.view.ViewGroup.drawChild (ViewGroup.java:3727) in android.view.ViewGroup.dispatchDraw (ViewGroup.java:3513) in
etc...

However, I had to go through several cycles to make my emulator work, but I needed to create a symbolic link so that I could run the emulator on AMD. Not sure if this is part of the problem. And in my life I can’t understand why he continues to do this. In my group there are others who simply emulate the project on the same emulated phone and SDK.

+44
android android-emulator android-studio
source share
7 answers

Move your image to (hi-res) drawable to drawable-xxhdpi . But when developing applications, you do not need to use a large image. This will increase the size of your APK file.

+112
source share

I have the same problem. If you try to download an image that is too large on some low-resolution devices, the application will crash. You can make several images of different sizes (hdpi, xxdpi and more) or just use an external library to load images that solve the problem quickly and efficiently. I used the Glide library (you can use another library like Picasso).

panel_IMG_back = (ImageView) findViewById(R.id.panel_IMG_back); Glide .with(this) .load(MyViewUtils.getImage(R.drawable.wallpaper) .into(panel_IMG_back); 
+8
source share

It turns out that the problem was the main image that we used in our application at that time. The actual image size was too large, so we compressed it. Then it worked like a charm, without loss of quality, and the application worked perfectly on the emulator.

+4
source share

In my case, moving the (hi-res) splash bitmap from drawable to drawable-xxhdpi was the solution.

I had the same problem. I did not suspect that my splash screen was a problem, because it is displayed when the application is running, but it turned out that the splash screen is a problem.

The screensaver in my case has xxhdpi permission, and it was mistakenly placed in a folder with the ability to transfer, not drawable-xxhdpi. This led Android to assume that the screensaver has mdpi resolution and scales the image up to 3 * 3 times when the size is required, and is trying to create a bitmap image.

+3
source share

In my case, I had to remove the Android platform and add it again. Something was stuck, and copying all my code to another application worked like a miracle - hence my idea to clear the build for Android by removing the platform.

 cordova platform remove android cordova platform add android 

I think this is some kind of cleaning that you should do from time to time :-(

0
source share

For this error, as others said, there was a large image (1800px X 900px) that was in the drawable directory, I edited the image and proportionally reduced the size using Photoshop, and it worked ... !!

0
source share

This can be a problem with Glide. Use this when you are trying to upload a lot of images, and some of them are very large:

 Glide.load("your image path") .transform( new MultiTransformation<>( new CenterCrop(), new RoundedCorners( holder.imgCompanyLogo.getResources() .getDimensionPixelSize(R.dimen._2sdp) ) ) ) .error(R.drawable.ic_nfs_default) .into(holder.imgCompanyLogo); } 
0
source share

All Articles