Xamarin Forms Out Of Memory Android - c#

I'm working with a Xamarin Forms app that uses a lot of button with images.
So after some time of navigation my android app crash, beacuse of out of memory problem.
How can I handle this problem?

You need to be very careful when dealing with images:
Before an image is displayed on the screen, it has to be loaded into
the memory.
Let’s assume you have a brand new device with full HD screen and 12 MP
camera. The picture you just took is 4000x3000 pixels large and the
total memory needed to display it is: 4 bytes * 4000 * 3000 = 48 MB for a single image!
What you need to do is:
Measure the view you’re showing your images in.
Scale / crop the large image accordingly.
Show only what can be displayed.
Above info from the below resources:
Read More : Here - Point #8.
Read More: Android (Walk-through on how to resize and crop images)
You can follow the same approaches using C# to resize the large images and display them efficiently.

Related

Drawing wide image in Xamarin.Forms Android

I'm having a bit of an issue getting an image (size 1.25MB, resolution 1080 height by 2520 width) to run on my android emulator. I can't figure out why resolution does this, but I'd like to preserve as much details as possible. So far I've tried:
Moving the image to different mipmap folders (no effect, image doesn't even get displayed and if drawable is say 120x480, that will be displayed, mipmaps don't work as source AT ALL for some reason).
Turning of hardware acceleration in manifest.xml (I'm assuming that's not a desired practice for release app). That works however the whole emulator gets really laggy.
Compressing image to smaller sizes. Still getting "trying to draw too large of a bitmap" error.
Any help would be appreciated!

How to scale window according to screen resolution in UWP?

I am new to Stackoverflow as well as UWP (My English is regular too). I apologize in advance for my bad writing.
I am developing a windows application in UWP/C#. My monitor size is 23' and it is set to 1920x1080 (100%) resolution.
As seen in image 1, I have configured the application in such a way that the size of the main frame is 1920x1080, therefore, when I run the application on my computer it looks perfectly (see image 2).
However, when I run the application on another computer with a smaller screen size (17 "), it looks like in image 3, where it can be seen that the application does not fit this size. It seems to keep the original size and mi application "does not fit on the screen".
My question is: how do I program the application so that it does not lose its shape, distribution, aspect ratio, or proportion when it is run on screens that are different in size from the computer on which it was programmed? In this way, it automatically adjusts to the resolution and scale of the screen, without losing the original proportion and distribution with which it was programmed and designed.
Thank you very much for your help and understanding.
EDIT 1: I am not looking for the content of the application to fit a change of the window, but rather to fit screens of different sizes. That is, the same content, distribution and proportion are scaled to fit on any screen size, as evidenced in image 3 that does not happen. (see Image 4)
I don't want the image 3 to happen.
The control doing exactly what you want is called ViewBox, but as people already suggested above, it would be better to design adaptive UI using triggers or at least grids.

Best way to render images as a video clip in a mobile device

I have tried to approach this problem several ways.
I have a web application that will load a sprite (which is a large jpeg that 'holds' 100 frames. Using the offset of div properties I am able to 'move' the image along so it looks like a movie clip.
This works well.
I need to produce the same on mobile devices.
I have to support Windows Mobile 6.5.
I was using jQuery/ajax to move the sprite image along to stop any flickering of the image within the browser.
Windows mobile 6.5 does not support this.
So, i decided to do a native app using C# Framework 2.0.
I thought about converting the sprite to a mp4 file and playing within a web browser control. but IE on the device will not support html5.
I have been told there is a CAB file from adobe so that I can play flash videos on the IE. But, apart from using ffmpeg to convert these images to a flv there is not much control as to adding menu like pause,stop,play etc when playing the flv file. I have not started any of this by the way i assume that would be the case.
So.. I thought if I download the sprite to the device i could use the graphics object of a picture box and render the rectangle of interest from large sprite to picture box.
I could not download the Sprite and save it to an image though. I get 'out of memory exception'.
I used the OpenNetCF.Drawing as it is supposed to support large files. I still get the error message. I have reduced the size of the image and it will work on about 20 frames.
I would then have to 'stack' these images containing 20 frames and load them up when necessary.
I am beginning to wonder now whether i am doing the right thing?
Is there a different way of trying to achieve what i am trying to achieve that is quicker and more efficient as I have run out of ideas.
If I am OK doing it this way then what is the best way to render images in a picturebox like a video. Memory efficiency says load the image from the file on the device when needed and dispose of it but that would cause 'flickering'. What IS the best way to handle multitude of images on a device?
i have plenty of code I can upload but I was worried the question would look 'messy' as I have tried so many things. I will of course edit/upload the code as required.
Thanks.

Zooming an extremely large image

Is there any predefined control in WPF or VS2010 to implement the Image Zooming functionality (like Googlemaps) for a bitmap displayed over a panel using C#? My bitmap will be minimum 8GB in Size.
Thanks in advance
Murali
There is DeepZoom for Silvelight. There is no such thing in WPF. It was planned for WPF4, but removed before RTM.
Update:
Loading images of this size is pretty uncommon. You should consider tiling as others suggested. Also consider if you really need load all data at once. If the image has size of for example 30000x30000 then the user do not really need/can't to see all this data. Use tiling and appropriate image format (jpg etc) for each zoom level.
Relevant links:
Single objects still limited to 2 GB in size in CLR 4.0?
Pushing the Limits of Windows: Physical Memory

How to load and manage images more efficiently?

I have a front-end program for PND's running Windows CE (both 5.0 and 6.0) It user a high quantity of images (currently in png format) as buttons or for decoration purposes. The images are loaded from the SD Card via the new Bitmap(path);
I'm currently using v3.5 of the framework.
Upon loading, OS + my application have consumed 75 to 80% of the device's memory.
Wich good ways are there to optimize all that files?
The only ways that come to my mind to optimise these picture would be to resize them to the real size they are needed (like most icons will be used in a 16x16 size) and if you store also as bitmap no your card you can also set the used color palette to a size that matches the exact needs of the given picture (e.g. a picture of 16x16 has 256 pixels. So you need a maximum palette of 256 colors, but maybe also a self-defined 16 color palette is enough, cause in your picture are only 16 different colors.)
As a second approach you could also check if you maybe have the same picture multiple times loaded. In this case you should load it only once and use it multiple times.
A last one, that came to my mind belongs to background pictures. If you have a solid background you don't need a fully sized image of it. Just take a 1x1 bitmap and stretch it to the needed size. The same counts for gradient backgrounds, but in this case you have a 1x2 bitmap which will be stretched. And last but not least if you have a regular pattern, just take the smallest unique brick out of it and use some tile mechanism.
If you create the OS, is it possible to store the images as part of the OS?
In case it is possible, and the image is loaded fully to RAM, you can load the images only on a need to display basis and unload them when not needed. This will eliminate some loading time as well since accessing RAM is faster than accessing the SD card.
Another trick in with the same concept would be to copy all the images to a RAM based FS and load them only on a need basis - the down side is that this needs to be done after every reboot.

Categories

Resources