I'd like to implement something like a slideshow on AndEngine. I need to show a big images(2000x800px). I'd like to have near 10 images but only 1 image can be displayed on the screen in one moment of time.
The main issue is memory management. I don't want to load all images in memory at once. I think the best idea is to load one image after the other(when the image is needed).
How to correctly load images in this way ? Also, how to correctly unload previous image from memory ?
Related
In the "drawable" folder I have four background images of 1024 x 768 or something.
However, it turns out to be that I have to use Bitmap.createScaledBitmap() and my Android device is 2560 x 1504. Which means a Bitmap with the size of 2560 x 1504 is required to fill the whole screen with a background, it is really memory-consuming because it is a Bitmap of impressive size.
For some reason, I need to cache 4 bitmaps like this so my program can instantly switch to a new background when I press a button. Which means I am facing huge memory problems now. Is there any way to optimize it?
P.S: I am using ImageView class to display images.
The images files in the "drawable" folder are not BMP files.
so basically, i'm new to java and android studio. I know the basics but I'm not that good yet.
I get this error when I try to run an the app on my phone. Going through other threads didn't help me either as I basically have just one background image in the MainActivity. I have to add one more but when I do it and try to run the app, it crashes.
size of background image: 115kb
size of the image I still have to add: 164 KB (tried to compress it to 74Kb, didn't work.)
java.lang.RuntimeException: Canvas: trying to draw too large(430377192bytes) bitmap.
I saw this in another thread which was supposed to be put in the manifest which hasn't helped either:
android:largeHeap="true"
I hope I have provided enough information needed to answer the question, if you need more please tell me.
Again: I am new to this.
430377192 bytes is the equivalent of a 10372 x 10372 pixel image. This is much too large. Moreover, it is far larger than any Android device screen that you are ever likely to encounter.
So, find this drawable resource, and reduce its resolution to something more reasonable.
If you placed this drawable resource in res/drawable/, please understand that res/drawable/ is a synonym for res/drawable-mdpi/, representing images designed for -mdpi screens (~160 dpi). Those images will be upsampled to higher resolutions on higher-density screens (e.g., double along each axis for -xhdpi screens). Either prepare dedicated drawables for appropriate densities, or move this image into res/drawable-nodpi/.
I've been looking around for a simple way to put graphic on the screen in android for a while now and I'm really confused.
I've a simple game written in java with swing for graphics and that's all I really need as the graphics doesn't really matter in this project.
Now we want to rewrite it so it works on devices with android and honestly I can't find a simple way to just put a image on the screen.
I'd love to avoid using complex game engine because I just don't need it. All I want is a possibility to draw an image (or 50 images) on x,y given by me and refreshing a screen every 100 milliseconds and I thought I'd be the first thing I'd learn in any android tutorial but well... it's not. Of course I know how to draw an Image with .xml but I need something more automatic - for dozens of images changing all the time.
So what is the best to do this? Isn't there really any way to do it with just some android built in function? If not what engine should I use just for the simplest things I mentioned?
A simple but not necessarily very clean way to do this would be to create an xml layout that is just an empty RelativeLayout.
Then you could create your images like this:
ImageView image = new ImageView(this);
image.setLayoutParams(new RelativeLayout.LayoutParams(IMAGE_WIDTH,IMAGE_HEIGHT));
//Other setup code for your image goes here
myRelativeLayout.addView(image);
This should give you an image of the specified width and height that sits at the origin.
Then you could move the image into position like this:
image.setX(IMAGE_X_POS);
image.setY(IMAGE_Y_POS);
When to do the moving is up to you as it will depend on when you know the positions that need to be moved to.
I have a widget with ViewFlipper that flips between X number of images. I aim for 10 images to be flipped, and I can do this if I load very small images. My widget is size 4x2 and I want to display images with good quality, but I can't achieve this. Everything loads fine, no exceptions, but the widget never displays them. If I load very small image sizes (100x100 px), it starts flipping them. If I load larger image size (300x300), it won't start flipping the images until I reduce the number of images (flips) to 4.
This suggests a memory limitation to me, but I would expect an exception to be thrown somewhere after I do appWidgetManager.updateWidget(widgetId, remoteViewFlipper).
Going through the logs, I don't see anything nearly related to this.
I think it depends on concrete implementation of launcher - widget stuff is hosted and processsed there. You updtes are send as parcelables, so there soule be data size limit as well:
http://groups.google.com/group/android-developers/browse_thread/thread/26ce74534024f41a?pli=1
I have an image file that has all the character sprites that I will be using in a game, and I want to make a layout that will allow the user to cycle through each image to be able to pick which one they want. So, I have one large image, and I need to render just a small (32 x 32) section of it at a time. Is that possible with the layouts or will I have to use a canvas, and manually do most of this?
Yes Try using scrollX and scrollY. You can set these properties programmatically or in the layout xml.
That said, loading just the small images that the user needs to see is preferred to loading a large image containing all. If your image is really large you might want to consider the first option.