Android Image application OutOfMemory again - android

I still dealing with my OutOfMemoryError problem, and now I'm in a hurry because we are reaching the project time limit.
I'm developing for an All-in-one android tablet (1920x1080 resolution)
My application consists on 3 views:
Book Category menu - Book menu (the list of books in the selected category) - Book pages display.
Book category, and book menu, are very similar:
One Horizontal Scroll View, that displays the list of (categories/books) (ImageViews added dynamically for each category/book in category).
When you click in one category, the application takes you to the book menu of that category, and when you click on a book, the application takes you to the book view.
The book view, is a copy of Android image_detail_pager and image_detail_fragment (Android's Displaying bitmaps efficiently Tutorial)
The 3rd screen (Book view), shows 4 images 1920x1080px resolution (full screen)
If I put that images in Android example project, OutOfMemoryError occurs again.
So, if Android's project fails, what can I do in my app?.
The other thing, in Android's example project, it loads the image from Internet, my images are already on disk.
Any ideas?.
Or I have to switch my application design to a Windows PC with a touch screen monitor and forget about android?.
thanks in advance.

You are running out of Bitmap memory. Can you use smaller images?

You need to manage the Memory Cache and the Disk Cache for your bitmaps to avoid OutOfMemoryError.
Look at his Google Developer link, Caching Bitmaps. You will find good practices to help you.
And you should also read this:
Loading Large Bitmaps Efficiently
Managing Bitmap Memory
If you need more info, ask me. I will complet my answer.

Related

Including thousands of images in Xamarin Forms application

I have a xamarin forms project for the company I work for. I have 6000+ images used in two ways : a thumbnail page and a full size page. I have both the thumbnail image and the full size image. The thumbnail page shows 12 products at a time, but it lives in a carousel page so it could have up to 18 content pages within the carousel.
I've tried three ways of saving/accessing the images:
Including them as bundle/android resources. This works the best but takes forever to build the project and on android will mean I have to use expansion files.
Included the binary image from the database when downloading the product listing. Causes the app to crash randomly on download.
Downloading all of the files from the web. This works, but on both Android and iOS, the thumbnail screen slows to a crawl and half of the time crashes on Android.
Has anyone had to do something similar and if so, what way did you decide to go? Unfortunately, this app does have to be usable offline so I need the images local. I'm kind of in a time crunch so any help would be appreciated!!
I had similar issues someday back and understood that it won't be successful with standard Image class with such a large amount of images (no memory caching, no task queueing, etc). Then I made CachedImage. It's basically an API compatible replacement for Image with advanced caching capabilities (and some other features). You could try that.
Just remember to use:
Downsampling feature : that way image would be resized to view size to save memory
Caching feature (it's enabled by default not including StreamImageSource for which you have to provide custom cache key factory)
Use FileImageSource (app dir) or StreamImageSource (eg. from image database) with custom cache keys
https://github.com/molinch/FFImageLoading (See WIKI for docs)

create a image gallery that cache and download images from the web with odd swipe action

I'm new to android development and I want to create a navigation concept which is a little weird for android and not sure what is the best way to develop this.
In a nutshell the application hold an endless collection of images downloaded from the server as the collection processed with buffering to make it smoother.
The general Idea is that I see the image full screen and have the ability to either swipe left or right, each direction represent a different action on the image and will show a small image near the image during the swipe to indicate which action I selected. Afterwards regardless on which action I selected it will swipe to the next image in the collection.
What would be the best direction to solve this problem, PagerAdapte or FragmentStatePagerAdapter (since I don’t have the ability to navigate back to an image)? Manually implementing the swipe using listeners?
Also how do I deal with showing the small images without making the code too awkward?
Should I use Volley for the image downloading?
Your answer is Bitmapfun. Try implement it. First screen of this application is gridview. If you click one of those items those images are shown in ViewPager you have to implement the ViewPager section. It also cached those images as you mentioned in your question.
Github link
Here is my solution to your problem:
First use volley to download images because:
1- Volley is open source and you can easily configure it, the concept behind it is very simple.
(for example you can change cache size, thread pool size for network requests and so on)
2- Volley uses two level caches, so makes you feel free about memory and …
3- Volley decodes images for you on the worker thread and that’s another problem you may face it but Volley solves it for you.
4- Volley handle configuration changes so on the flight requests dose not duplicate if orientation changes and you request them again(for the first section)
5- You can ask volley to deliver you an image in a different sizes so your thumbnail image and real image all can be delivered with just changing the request image size
6- You can change the HttpStack of it to run on a OKHttp , which is more optimized for all version down to I think 2.2
All you need to do is just spend some time to understand it and configure it to get most performance from it and use it’s two level caches to show your slides.
For showing the images I do not recommend you any of FragmentPagerAdapter nor FragmentStatePagerAdapter because:
FragmentPagerAdapter is not suitable for large collection of fragments because it store all fragments in memory and you will soon get OOM exception.
FragmentStatePagerAdapter is good because it handles configuration changes but it also stores at minimum 3 pages in memory which one of them is the last page you just visited so because you do not want to go back to last image it wastes memory for you.
I think best solution is manually implementing the swipe using listeners with the idea of off screen loading, to load for example two next images in memory.
Have you tried AndroidImageSlider. It is open source and has some pretty awesome features.
you can refere this " https://github.com/Dreddik/AndroidTouchGallery " link hope it`ll helps u :)

Thumbnail creation. On the fly or create small image?

The question regarding thumbnail creation seems to get asked a great deal, and each time there seems to be a great many different solutions proposed. From my experience none of the supplied answers are actually sufficient and all seem to have their own flaws.
a) Memory issues when re-sizing
b) Performance issues / slow to render
I therefore wanted to post a question regarding a very common functional requirement that I am hoping someone can assist with.
'User generates a report using activity and takes associated photo using internal camera. The report along with the image path is saved to SQLLite database. User wants to view reports in a scrollable list view at some point in the future. Number of reports could be 1..100'
So given these requirements the questions I have are as follows
1) Given that to data I have not found a reliable / performent / memory optimised way of resizing full size images at run time to a given thumbnail, should I create a smaller image at image capture time?
2) If you need to display many items in a ListView should you use paging or should it be possible to display a 100 items in one ListView?
Thanks
Regarding number 2: What you could do is load a subset first (say the first 30, depending on your listview item size), and load the rest asynchronously and append them to your adapter. This will decrease the loading time of your screen.
1/ Why do you want to reinvent the wheel :) There are libraries that already do for you and do it well. See picasso or AQuery for instance (there are other libraries too).
Basically, they have a thumbnail cache somewhere on the SDcard/internal memory to keep last N requested thumbnails.
I don't know if you are keeping the image data within the database, in which case you may have to adapt one of those libraries to load the image data from the DB and not from a file as it is usually the case.
2/ Why do you want to reinvent the wheel :) There are libraries that already do for you and do it well. See https://github.com/commonsguy/cwac-endless for instance (and google for more)

Adding images to application at runtime

I'm developping an application for custom menu navigation in restaurants. I have finished my demo app for presentation purpose. My app contains a bunch of images that i added to the resource file. Now i want to create a short installation that gives people the opportunity to add their own images & menuitems to the App at runtime. Here's a screen of my app:
The images would be located on an AzureBlobStorage. A person will be able to give a unique key ( GUID ), the app would then connect to the azure MobileServices where a database is located, containing all the MenuItems ( Name, Category, ImageName,... ) and map it to it's own local SQL lite database. The images are .PNG files with 2 different dimensions. ( 150x150 & 1072x611 )
My question would be, what is the best approach for adding images to the application once the .APK has been created without losing speed?
Nothing you can do about the speed of retrieving from Azure (short of selecting a cloud service based on performance but Azure is probably as good as any) and assuming your SQL code is efficient, the Q becomes where and how to store/retrieve and how to keep the UI responsive as you download and install the images.
I would store in private storage since it's generally much higher performance than SDCard and has fewer unknowns.
You should also scale down the bigger images to the minimum resolution that still works on your highest resolution target devices for your UI. Remember that a bitmap in memory takes x*y*4 bytes by default which is about 2.6MB each in your case.
Android: high quality image resizing / scaling
I assume that the main UI you have shown is a ListView of some sort so you should be implementing lazy loading of the images and definitely recycling them in getView() in your underlying adapter.
Lazy load of images in ListView
There is not much you can do about the speed to download from the cloud so you should be doing that on a background thread, e.g. AsyncTask, and using placeholder images in your list view until the actual image is downloaded. Use notifyDataSetChanged() on your adapter to let the list view know that there's been a change.
http://android-developers.blogspot.co.uk/2010/07/multithreading-for-performance.html
http://codehenge.net/blog/2011/06/android-development-tutorial-asynchronous-lazy-loading-and-caching-of-listview-images/
Finally, if you really want a good Android OOP solution, consider implementing a content provider.
http://developer.android.com/guide/topics/providers/content-providers.html#creating
What is the use of private Content Providers?

display album folder as a stack or deck android

I want to categorize the images on my device and display it in different albums where the albums look like a stack or deck of images. This is quite a common feature in the default gallery, or applications like QuickPic etc.
How is this achieved? Is it a straightforward effort?
What is the estimated time reqiured for this effort?
You can get the images from the device and put them into different folders. Your app logic would recognize each folder as an album. Then a layout would be created which would display each album with the top 3 or 5 random images in it as a deck of cards (use a relative layout for this to place images on top of one another and use can use a transform function to rotate them slightly if you want also). For each album you would have one deck of cards,and when the user selects an album, you would launch another activity which would be your custom android gallery for displaying the images in a particular album. Here's a good tutorial for how to build one of these custom galleries:
http://mobile.tutsplus.com/tutorials/android/android-sdk-displaying-images-with-an-enhanced-gallery/
As for the time requirement, it's really depends on your skill level. It can range from about a week to 2 months or more I suppose. It isn't very hard to do once you get the hang of the basics of the android file system, a bit of graphics and manipulating the gallery.
Hope this helps :-)

Categories

Resources