Loading Heavy Images on Pyagme Subset for Android - android

I am new to using Pygame for Android and I have been trying to convert my This Game to an android game. Here I need to load around 6 images in one screen but when I try to load more than two images, the apk-application closes down abruptly (it works fine on PC). Here is the complete code of what I have done so far.
Is there any way I can load multiple images without making the game unstable for android?
Note : I am using Pygame Subset for Android to convert my .py to .apk

Yes you can, use Picasso library for loading the images. I had the same problem with OutOfMemory exceptions, but this library solved my problem.
Download the Jar file and include it to your project, but before that make sure you read the documentation, it's very short and simple especially the IMAGE TRANSFORMATION part.

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)

Can Android handle computations in image processing and ttf rendering?

I am planning to create an Android application that will enable users to draw their own font. One similar app I found, they render the drawings online and sends the ttf file via email. What I want in my study is to render offline and saves the ttf directly into the sd card. Do you think Android can possibly do it? I am worried if it can handle all the computations of the first step which is image processing and handle those parameter requirement in rendering into .ttf (TrueType) format.
There's no reason why it wouldn't be able to.
If you can't find a API function that can do this, you can always write a small native library (using NDK), and use the FreeType open source library to do the rendering.
If you need an example of character rendering to OpenCV images, look in this short code:
https://github.com/amirgeva/optmatch/blob/master/src/chrmatch/ftfont.cpp

Animation in Android's WebView

As far as I know, swf's and gif's inside WebViews are not officially supported by Android, eventhough they work in my HTC Desire Device.
I'm building an app that it's all based in a WebView. What i did is code the 'app' as HTML, put it into the 'raw' folder and once the app starts, it puts all the htmls and images into a folder on the SD (if they're not there yet).
Now I need display some animations in there. I made them with Actionscript and I was glad that it seemed to work (Animations were 25KB each), but after a while publishing it, i got reports from people that coulnd't see the animation.
Then I patched them into a GIF (raised memory to 400KB-1MB each). At this point, I decided to take the gifs out of the raw folder, and download them from one server in the web the first time the app runs, so my apk doesn't get too big. But I get complaints again that people can't see it (then I found that GIF is also unsupported)
Google-ing and stackoverflow-ing I found that the only solution is to split those GIFs into separate images and show them with javascript one by one to create the animation. I guess this method is OK for small animations (like some face saying hello or something like that), but for whole animations.... It weights about 3MB per animation (when the swf was 25KB...). And I think taking 30MB (possibly more in the future for new animations) from user's data quota is not nice.
So:
Is there any other solution?
Are there lots and lots of phones that don't support SWF? and GIF? If they're not too many, I would consider putting on my app's description that the animations won't work if the phone has low memory (animations are not very important into my app)
Thank you very much,
VĂ­ctor
edit: Additional information: Animations are like this one.
So... I found the only way was to use HTML5 canvas animation, since surprisingly it is supported by many devices.
The animation is not as smooth as in a GIF-compatible device, but I rather make it accessible for everyone.
So, CommonsWare answered my 2nd question, but I will answer my 1st one: Yes, use HTML5. It didn't take a huge work, since JS can be Object-Oriented as well, and syntax is fairly similar to AS3.
And the best part is that the base code only weights 34KB (let's say the engine plus all the images), and each animation (in a separate file) weights between 1 and 2KB. That was awesome, I can put them all into my Android's raw folder.
Thank you very much CommonsWare for your comment.

Open CV Vs NDK for Image processing

I am writing a program to manipulate images,ie change its color,brightness,contrast etc...
The DVM doesn't support the manipulation of images of size beyond a limit...Can any one tell me whether using Open CV will solve the issue(as this seems to be a better option than NDK)?
Or will I have to use NDK?
I have done a lot of search and was not able to find answer..
First of all, there are different options for Image processing in Android, see here for a comparison of the most popular options: see Android Computer Vision JavaCV OpenCV FastCV comparison and Image processing library for Android and Java
Coming back to your question: If the images you deal are really very large so that they do not fit into the memory of the device, you need to process the images in small chunks called tiles.
If your images are not that big, I recommend you to use OpenCv, if you have to do anything more than very simple tasks such as brightness/contrast adjustment.

How to merge two or more bitmaps using NDK?

I have a painting application that is running out of memory on a few devices really quick... :(
The problem is that I have bitmaps that are screen size and I'm loading 2 or 3 images to memory than I create a blank bitmap attached to a canvas for merging the 3 images into it. So yeah lot of bitmaps...
My goal is to use the NDK to load the images from file merge them and return only one Bitmap. Well essentially in java I would create the empty image and pass the object to the NDK. This should alleviate the amount of memory used on the device. At least in theory...
The first problem I'm facing is decoding the png image from file. How can I do this via NDK? Should I use BitmapFactory via JNI?
Than the bigger question how do I merge these ARGB bitmaps?
I am not familiar with what image manipulation abilities are built into the NDK, but the OpenCV library can be included for use in the native code, and that is what I use (largely due to previous familiarity, but it is really nice).
Here's the OpenCV 4 Android project. Here is how you would open a PNG.

Categories

Resources