I have a published app that is crashing at startup on Android N when the newly introduced Display size OS setting is set to too large a value.
When I look in logcat, I see the following message:
java.lang.RuntimeException: Canvas: trying to draw too large(106,975,232 bytes) bitmap.
I've traced the issue to an ImageView in my first Activity that shows a nice big background image. The image in question is 2048x1066 and is in my generic drawables directory, so no matter the density, this image will be used.
Everything works okay when the Display size setting is Small. But when I go up to Default, it stops working. If I then swap the image out with a smaller one, it works at Default, but if I go up to Large, it stops working again.
My guess is that adjusting Display size up causes your device to behave like a physically smaller device with a higher pixel density. But I don't understand what I'm supposed to do here. If I put in progressively smaller images for progressively higher resolutions, it won't look good on actually large displays. Or am I not understanding something?
Any pointers would be greatly appreciated.
I my case, moving the (hi-res) splash bitmap from drawable to drawable-xxhdpi was the solution.
I had the same problem. I didn't suspect my splash screen to be the problem, since it is displayed when the app is started, but it turned out the splash screen is the problem.
The splash screen in my case has xxhdpi resolution, and it was mistakenly placed in the drawable folder, instead of drawable-xxhdpi. This made Android assume the splash screen had mdpi resolution and scale the image to 3*3 times it's required size and trying to create a bitmap.
I solved the problem after adding the below code into the Manifest file's application tag in between android: lines.
android:hardwareAccelerated="false"
I don't know would it help some one, but I'll just leave it here.
In my case - problem was only on Sumsung devices with Android 7, and problem was in splash screen proportions. after changing height to 1024 px - everything works fine
Move your image in the drawable to mipmap-xxhdpi.Your image is in bitmap format so you should put your image in mipmap folder,then it will work
There are some scenarios where Original Bitmap needs be Drawn into ImageViews, Photo Editing apps etc...,
as bay mentioned above setting
android:hardwareAccelerated="false"
will Cause bad UI experince, You can set hardwareAccelerated Only one selected Activity where high res image to be drawn
<application android:hardwareAccelerated="true">
<activity ... />
<activity android:hardwareAccelerated="false" />
</application>
Try to use Bitmap.Factory class, this link will help you
Loading Large Bitmaps Efficiently
if you use Picasso change to Glide like this.
Remove picasso
Picasso.get().load(Uri.parse("url")).into(imageView)
Change Glide
Glide.with(context).load("url").into(imageView)
More efficient
The icon files are too large for Android to efficiently and smoothly load. Android recognizes this with its smart algorithms.
You can resize the icon files using Final Android Resizer by asystat. Resize them to "xhdpi" or lower.
Place the resized photos in drawable or overwrite over the existing large icon files.
Then, you're done.
if you are using glide and you are loading 1k of images at a time or some images then it is issue of glide or whatever you are doing to use to set the image view. you can resolve it just by applying scale type in glide.
In my case, I just changed the canvas of image which is used in the background using Paint3d(or you can use any other). Here I am sharing a screenshot just go through it.
it is solved by resizing the images to a lower size.
Need to add Manifest file's application tag in between android: add below lines.
android:hardwareAccelerated="false"
Just an addition to the Johan Franzén's answer, maybe it's a good idea to not only add drawable-xxhdpi density folder, but also add another density folder.
So whatever the android version and size, your app can prepare the image source with the right size :
Change your folder view on the top left from Android to Project
Go to YourProjectFolder folder > app > src > main > res
Prepare the original image with your best resolution, and split it into each folder size automatically. You can do it in Baker
Then create a folder with another density, namely:
drawable-hdpi, drawable-ldpi, drawable-mdpi, drawable-xhdpi, drawable-xxhdpi, drawable-xxxhdpi
Put each image into the appropriate folder
i solved the problem by simply changing the image extension to .png extension, and it worked just fine with me.
My ImageButton in my app is very tiny and cut off. I realized this could be because the image was in the drawable folder instead of the mitmap folders. So, I copied the images from the drawable folder, and pasted them in mitmap folders. Now, should I go about deleting the image from the drawable folder? I get the following saying it is not safe:
I know how to access the images, but should I delete them from the drawable folder now that I have already moved them to the mitmaps? If I do a delete anyway, will I need to alter my code to access the mitmap image? What is safest to do?
Here is an image of my mitmaps:
Thanks for the expert advice,
Rich
"Not safe" in this context just means that it's still being used somewhere. If you delete it, the current usage will fail to compile, and you'll be easily able to find and alter it to point at the new location.
You can safely delete this image, in Android Studio if you are using this image or else the file will be open at some place, you can get this error actually, so try deleting this image will safely remove the only selected image into your workspace. So hassle free to delete it.
After deleting your image, clear your project and run it, it works fine.
The mipmap folder is used for image that are very small and should be used in the action bar, and other menus. If you find your image too tiny, it just will be worst if you put it in the mipmap folder. If it's tiny although the image is in the drawable folder, maybe the image has a very small dimension or your imageview is too small.
I use the following statement to copy an image from the assets to the gallery app, which works fine:
MediaStore.Images.Media.insertImage(getContentResolver(), myBitmap, myTitle , myDescription);
The images are png-files with a transparent background. They are displayed correctly when I load them from the assets to, for example an ImageView.
The problem is, that the formerly transparent background of the imported images became solid black in the gallery.
The png is a png24 created by gimp. I also tried a transparent gif and a png with transparency added by Apple's preview application with the same result.
Why it happens?
I know this is an old question but I just had the same problem. The problem is that MediaStore.Images.Media.insertImage stores the file with a MIME_TYPE of "image/jpeg", and jpeg doesn't support transparency.
One solution is to make your own content provider that uses another image format. The Picasso image library might be worth a look too.
I have an application in which i am setting the background of an image view.
If i keep my images in the re/drawable(s) folder, everything works fine but if i keep the same images in the sdcard and load from there to set the background then the dimensions of the image are different.
A similar question had been asked earlier but it is still unanswered. Could anyone shed some light on this topic.
if we place the images in res/drawable(s) folder then android chooses the appropriate image according to target device and scaling is also done by system if required. So if you are putting a image in sdcard then system does not do any scaling on image.
My Problem: Only one image will actually load from the assets folder. I have all the images there and when I try to access any of them I don't get an error. By actually load I mean it shows the image on the screen. When I load the other images the whole screen comes up white.
In every instance I am loading the whole image to the whole screen.
If I were to put the image as a fourth its size in the middle of the screen then there is a white rectangle there. The image is supposedly in the .apk because I don't get an error for the game trying to find it. However if I were to load this one image then everything words fine.
The one image that works find is a .png image and I tried to load the others as a .png but it does not work.
Any advice on where to start?
I load the images through the AssetManager.readAsset() as an input stream and then use the bitmap factory to get the image as a bitmap. Afterwards I load the bitmap into open gl and draw the region I want. However, the problem is only my first image I ever started using works at the moment. Could there be something wrong with a file that eclipse generates?
Some png bug android.
Just try to open them and save them with gimp. Sometimes it solves the problem.
Finally found the solution.
Turns out that one image that worked had a bit depth of 32 and the other ones only had a 24 bit depth.
The solution is to open up the image in gimp, add an alpha channel (makes it 32 bit), and save it as a .png file. Then read the details and it should say it is 32 bit.
Thanks guy! :)
Also note that images have to be by power of 2. For example it needs to be 1024 by 1024.