How to prevent a drawable from becoming blurry? - android

When i copy-paste an image to the drawable file, i get one image with the original resolution. When i use the New--ImageAset way i get a lot of images for different screen densities but they are all blurry, even xxhdpi! How can i have the different densities inages without this problem?
Im surprise i didnt noticed it before!
I read this but it hasnt helped me
Android ImageView blurry?
http://developer.android.com/guide/practices/screens_support.html
Any advice am i doing it wrong?
EDIT
I tried the AndroidAssetStudio but it still happens
Before
After (xxhdpi)
Cant i get it to be the ldpi and then make it scale up from it or something?

You can create your image in different resolutions using Android Assets Studio. Then, copy paste the image to the respective folder. This will give you a proper image, without blur.

There is a plugin exactly made for the same purpose. You can use that plugin to make different sizes of the same image. You have to copy/paste a single image in drawable folder. Then right click drawable folder and select
NEW>Batch_Drawable_Import. Select the size for your image and it will itself make the other sized images for you.

Related

How to load images for different densities from server

I have an expandableListView in my activity and passing data from JSON that I get from server. Everything is working fine Except the image part.
I'm getting image path as string within JSON for different sizes (48x48, 72x72, 96x96 etc.) but unable to figure out how to assign image according to the screen density. I think I can Add these images into the corresponding drawable folder and android would do the rest. But on searching I did not find any example on how to add images in drawable folder dynamically.
If there is any way to add images dynamically into drawable folder please let me know OR suggest any other appropriate solution.
You can't add images dynamically into the drawable folders.
But you can get the device's screen density programmatically. You can use that value in your api and return appropriate image(s).
You must understand whats drawables in android by this link
and you must know that you can't put any images into them dynamically, icons and static images must be into drawables folders, for other images which you are using them into application you can get image and thumbnail
it's not possible to save in drawable at runtime.
you can't use assets folder too.
if I were you it I didn't bother my self to determine screen density. use Glide and Picasso in order to load image asynchronously.
Update :
the thing that i should mention is that, if the ImaveView is a fixed size view by dp it'll appear "the same size" on all devices as per Android's specs.
glide and Picasso read the view size by pixel and then scale the image to that size.
I prefer Glide because it has a smaller memory footprint by making some different assumptions like caching the resized images instead of the full-sized images.
Edit:
#greenapps you are completely right. it cannot be saved in assets too. try to create a directory and save drawable into that

How to set app launcher image from drawable folder?

Instead of using multiple images of multiple sizes in different folders like mdpi,ldpi,hdpi etc, can i put single image in drawable folder for app launcher icon so that i can reduce app size. What should i do for that.
Probably, try changing your manifest from the mipmap directory to the drawable one. If it doesn't work, I suggest just using a mipmap version with all the different sizes. If you think preparing the different icon sizes is difficult, it's not:
When you add the launcher icon, android studio will offer you to auto generated the various densities for you while you're in the image selection bit. So, you only have to add one image, incase you thought you had to resize them.
Its simple,generate icon of largest size ,which u think u may need anywhere ,and put that in your drawable folder. Android will automatically resize and use it according to requirement , This way you can effectively have just one image and let android handle sizing

Shall I put 9-Patch Image in different drawable for different screen size or i can place it only one time in drawable for different screen size?

I have one 9 patch image but i don't know that where i have to put it. only one time in Drawable folder or i have make different folder ( like mdpi,hdpi etc) in drawable for supporting different screen resolution.can anybody suggest me.thanks
Nine Patch images are mainly used to reduce the number of images. So if you are using nine patch, there is no need to use it in different folder we can use it drawable folder alone. This will reduce the number of resources used in the project, which will obviously reduce the apk size too, etc...
Hope this is helpful :)
Both drawable/ and drawable-*dpi/ work.
But I put all drawable *.xml files in drawable/, and all png/webp/jpg files in drawable-*dpi/, which makes the folder cleaner.
As u may use different *.9.png for different screen resolution respectively, drawable-*dpi/ may be a better choice.
Hope it helps.

"Canvas: trying to draw too large bitmap" when Android N Display Size set larger than Small

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.

Cannot change the image background in android using eclipse

I have a problem in changing the image background in Android using Eclipse.. I already replaced the previous image but then when the emulator run it always appears the replaced image.Pls help to solve this.Thanks
So what you are saying is that even after you replaced the images those images are still shown. Make sure that you replaced the previous images in all of the drawable folders. Because if you just replaced the drawable-hdi images but not the drawable-mdpi ones than if the emulator or device has a mdpi screen it will load the mdpi images from the drawable-mdpi folder thus showing the older images. So make sure you replaced all the images and not just in one folder.
Simply add android:background="#drawable/backgroundmenu" in your Layout section in XML activity
But first, import an image called "backgroundmenu" in drawable.
you need to clear your files in drawble folder in this location; ..\eclipse\workspaces\YourProjectName\bin\res\crunch\drawable
clear all files there, good luck!

Categories

Resources