My application has an activity with metro schema, so for good quality I need to put image with resolution more then 2000x2000, but such images use much memory and application crashes with Out of memory error.
Does this problem will solve when I will change the image source to SVG (by svg-android for example)?
It depends on the complexity of image simple vector re presentable image will defiantly improve the performance otherwise complex images will use more memory.
more Details here.
Related
I am developing an Android app which has hundreds of .jpg files (over 300) each one of around 40kB. I would like to know if there is a way of reducing the size of my app. I looked at a similar question here Reducing Android App Size, but the problem still exists. Is there perhaps a way to compress the images and decompress them in real time when needed, or any other way to make my app more space efficient while not sacrificing speed?
If you have used tinypng for every resource you did your best with this kind of solution. In general, it's better to use vector graphics where the general icon will be <1kb. Also, a vector resource can be animated. If it's quite simply bitmaps, you can generate them in code on demand. Also, you can divide your app by dynamic features and each will be downloaded on demand with their part of the resources.
Is there perhaps a way to compress the images and decompress them in real-time when needed?
There is no standard Android solution out of the box. Probably, you can write something on your own. But this looks like too much effort.
Still, the most practical solution: use vector graphics as max as possible, generate in code what you can generate, compress with tinypng the others. That should be enough or you should have a very good reason for making some extra work.
For more info about vector graphics in android. For standard vector graphic import right in the android studio.
Web-site where you can download icons and insert them into the project.
In my android app,I am displaying various images from gallery whose paths are stored in a database and on runtime it uses bitmap to display image from these paths and due to this it is consuming lot of memory.It is crashing in many mobiles although I am reducing the quality of image. Is there any other way to do this?
I'd strongly suggest looking into image libraries such as Picasso and Glide. Displaying bitmaps natively in Android requires a fair amount of coding to ensure issues like Outofmemory error do not occur.
Let's say I have 100 PNG files (images) I want to use in my Android app. If I add them all in the drawable folder, would that be a performance impediment? If yes, what alternatives do I have?
I mention that I won't use them all at the same time. Most probably, I will need 6 of them at any given time.
Only storing them in a folder would not be a performance impediment.
As long as you do not load the images in your code, performances are not involved.
Then it's up to your use to choose to load them all at the start of your app, or on demand when your app is running.
It shouldn't impede the performance of your app in any way, however you may want to consider clever ways of compressing the images to reduce APK size or the times to load individual images i.e vector drawables or webp.
See https://www.youtube.com/watch?v=r_LpCi6DQME
I use an image loading library (Picasso) to do image loading/display for remote images, and it works very well. However, for local resources (mostly smaller image icons) I've been simply putting the image directly in the xml (via src="#drawable/image_name").
Should I also be using Picasso (or Glide, etc) to load these smaller local images? If so, should I do so for both lists (shown via RecyclerView) and one off icons? Currently loading these local resources w/o a loader is working, but I would like to improve perf if possible.
Thanks!
Standard practice for local density specific resources that are included with the apk is to just load them via resources, either by including them as src or background in xml or using Resources#getDrawable().
Usually an image loading library is unnecessary for local resources because local resources tend to be small, fast to decode and are frequently already in memory in the resources cache managed by Android.
That said, if you think you have a performance problem, measure! If it looks like a particular image heavy Activity or Fragment is slow to start because of layout inflation time, you may want to experiment with using an image loading library for resources. Using an image loading library is also probably appropriate if you're loading raw resources, or resources that aren't split by density.
i have made an image editing application for android and i want to edit large images that there is not available memory size to load all of their data into it. Is there any library that provide api that load and stores part of an image so i can have an edit only a portion that fits the memory? Photoshop for android can edit images up to 1600x1600, how this is possible?
You can use matrices to scale the image, take a look at this code Is hard to understand, but it might bring you some light.
You can use BitmapRegionDecoder to elaborate blocks of the large image.