Currently Im developing fling action (similar to that one implemented in IPhones gallery app) in my custom view (image as background + some other staff). I have already working code, but I am thinking if there is a way to increase performance. My idea is simple: I pass 3 bitmaps to view: previous, current and next. When user perform move action on the screen he can see current bitmap + next/previous depend on the movment direction. A big dissadvantage is that I have to have 3 bitmaps loaded in memory all the time. I am using drawBitmap method to draw resized bitmaps to the screen and BitmapFactory to load it. Sometimes UI is not responsive for a while. I think it because there are only space for two bitmaps in memory so one is recycled and have to be reloaded by system. Also in my plans I have also scrolling in vertical directions so that will give me another two bitmaps cached in memory. Is there any chcance to improove performance in my solution, or any other solutions? I was thinking about extending gallery widget, but I need zooming and vertical scrolling also.
Related
background
I've made a simple app called "LWP+", which shows a cropped image . When the user chooses a photo, I save it into a file, and then do the cropping when needed. I do this by using 2 libraries. One for allowing the user to choose the cropping rectangle, and one for the actual cropping.
The problem
This is just for a normal cropping, but a nicer feature I'd like to add is a way to scroll through the content of the entire given image, at least horizontally.
On a normal Activity, I'd probably use a ViewPager that has an ImageView for each page.
But here a live wallpaper doesn't really have a layout.
What I've found
There isn't much of information about live wallpapers in general, but when I've searched for scrolling of an image in it, I've found just how to move the canvas.
This can actually be a good idea, of somehow having bitmaps (or partial decoding of the image) around the current position, and translating the canvas as needed. I could also use a GestureDetector class to identify flinging, but this is only a tiny fraction of what's needed to do a nice scrolling of a zoomed image.
It is also very complex, as it requires good memory considerations in mind.
If I could use a normal view, I could have used a ViewPager, or even a third library that shows an image and allows to scroll in it freely , like in the gallery app (such as this one).
The question
Given a View of any kind, such as ViewPager or another, is it possible to host it somehow inside the LiveWallpaper, to let it show content, and to handle touch events ?
Alternatively, is there an efficient way to view content as I've written, yet in a live wallpaper? Meaning viewing a portion of a large image, while allowing to scroll though it (like a ViewPager, but maybe even freely like on a photo viewer library, in all directions) ?
I have to show 64/64 bitmaps in a grid of 1100/1100 but the scrolling is not smooth. What is the optimum way in displaying such ammount of image data?
This is just too much memory consumption for an android app.. I don't think you really want to load all of those at the same time. I would rethink the requirements first.
There should be a solution that still satisfies the user and does not load that many views into memory. I don't know what is the use-case here, but I would suggest implementing something like paging. Load a limited amount of items, and only if user wants to see more, then show progress bar and load more.
E.g. you can load more if user scrolls to the last item, or just create a button like "Show more". I'm not sure which solution will be okay for your app. Also, I would actually load new items into the same GridView replacing previously loaded bitmaps, because each of them requires a lot of memory. You can always control the scrolling position programmatically if needed.
We want to show in an Android app a list of images in the similar manner with many gallery apps: horizontal sliding by using a gesture to show the next/previous image.
Also the image viewer should support zoom/pinch (besides other features).
Images can came from a database or from a directory and can be as much as 200-300.
The question is: Which is the best way to implement the slide-show part from the environment described above?
Through animations of a two TImage? There exist a specialized component for this? By using Horizontal Scroll box?
Stick 10 TRectangle objects in a THorzScrollBox. It could be more or less than 10 depending on the memory that the device has. Align them all to alTop. Load the images for display in TRectangle.Fill.Bitmap.Bitmap.
When the user scrolls down and is near the bottom of the ten, move the top rectangle to the bottom of the chain and load the newest image from your list into the new bottom one.
When the user scrolls up and is near the top of the ten, move the bottom rectangle to the top of the chain and load the newest image from your list into the new top one.
The reason behind doing it this way is that TRectangle is a really light image display container and you are recycling the TRectangle objects instead of deleting and creating them all the time.
It is possible that you will experience a display pop when you move the next TRectangle object to the top of the chain or when you move it to the bottom of the chain. You will have to create code to take care of this either by setting the position on THorzScrollBox or decreasing and increasing the height of the TRectangle as it leaves or enters the view until it is full size.
If you have installed samples with your Delphi instalation then you can find several examples of how to do this in:
Samples\FireMonkey\Fireflow
Samples\FireMonkey\MetropolisUIFlipViewDemo
Maybe there are even more of them. I haven't checked every sample so far.
I've got custom sliding view, which I can move up and down, over another view (ImageView).
I've also got blurred version of said view prepared in memory. What I want to achive is blurring this background view during sliding up/down as I would cover it with a blurry glass. Also, I need to reverse this process too, that's why I'm keeping both Bitmaps.
Hope I made myself clear here.
sadly, this project requires me to use API >= 8
I have a very large image (a map) that I need to display. I already have the image in "tiled" format - 256x256 pieces.
Also I got tiles for several "zoom" levels.
At the moment the issue is to display the deepest zoom level, where you'd have really a lot of tiles.
For example, a medium sized map will contain 4 rows and 26 columns of tiles for deep level.
I tried approaching the problem using a 2 dimensional scroll view and image views inside it - 1 per tile.
The problems is that it crashes. When I try displaying 4 rows and 20 columns it doesn't crash, obviously it's a memory issue.
So the question here - how to display all that, taking into account limited phone RAM.
I do understand there should be a way to dealocate memory for images that are out of sight, and only display those which are currently in visible area of the scroll view, but I don't know how to do that.
Would be happy to hear any clues or maybe there's alternative approach to these things.
Thanks.
I think you might better use the grid view instead of arrays of scroll view (but I am not sure if it support side/updown scroll at the same time.
And then in your adapter, override the getView method. There you can control the recycling of your images.
The project I am doing also have issues with image and RAM, what I am basically doing is like:
image.recycle();
System.gc();
I tried doing the above stuff like 50fps with the image is like 800x400x32bit and still not running into out of memory issue. But if I take away the System.gc(), it crash immediately.