My Problem: Only one image will actually load from the assets folder. I have all the images there and when I try to access any of them I don't get an error. By actually load I mean it shows the image on the screen. When I load the other images the whole screen comes up white.
In every instance I am loading the whole image to the whole screen.
If I were to put the image as a fourth its size in the middle of the screen then there is a white rectangle there. The image is supposedly in the .apk because I don't get an error for the game trying to find it. However if I were to load this one image then everything words fine.
The one image that works find is a .png image and I tried to load the others as a .png but it does not work.
Any advice on where to start?
I load the images through the AssetManager.readAsset() as an input stream and then use the bitmap factory to get the image as a bitmap. Afterwards I load the bitmap into open gl and draw the region I want. However, the problem is only my first image I ever started using works at the moment. Could there be something wrong with a file that eclipse generates?
Some png bug android.
Just try to open them and save them with gimp. Sometimes it solves the problem.
Finally found the solution.
Turns out that one image that worked had a bit depth of 32 and the other ones only had a 24 bit depth.
The solution is to open up the image in gimp, add an alpha channel (makes it 32 bit), and save it as a .png file. Then read the details and it should say it is 32 bit.
Thanks guy! :)
Also note that images have to be by power of 2. For example it needs to be 1024 by 1024.
Related
I am getting an issue when I try to load set of images in View Pager in Android N (checking Samsung S6).
java.lang.RuntimeException: Canvas: trying to draw too large(132710400bytes) bitmap.
Image dimension is 960*720 and its size 64 k, View Pager count is 4
Now I place all the images in normal "drawable" folder. I tried by replacing all the images to "drawable-xxhdpi" but the issue still exist.
Im my case i resolved it by going to my manifest and changing hardwareAccelerated from true to false. android:hardwareAccelerated="false",
Nougat is pretty smart in optimisation. It doesn't matter in whichever drawable directory you put it in. It will detect whether the image is suitable for the fluent working of the app or not. And if it is not then it will generate this exception.
Solution:
Use Final android Resizer to generate drawables for all dpi.
Use Glide library to load bitmaps efficiently (it supports bitmap caching and bitmap pooling).
If your image is of single coloured (like icons) then you can generate vector drawables from .SVG or .PSD files. Learn more here.
Good luck :D
i am developing kids 1 to 100 learning number speaching application. here i used nearly 100 images used to refer the every images.
i have two two levels. dynamically creating buttons, runtimely load images into buttons here.
one is for number showing with images level.
another one is for alphabetic with images showing level.
totally i used 150 images from drawable folder.all images are PNG format with width and height is nearly each one 240 into 210 like that..
when i click NUMBERS level button , that part working fine. when i get back second alphabetic level its completely application crashed.
Error is: Out of Memory error only..
I refered this stack link : Strange out of memory issue while loading an image to a Bitmap object
they told like, get the image and decode and load it into drawable.
here exactly i dont know , how to get image from drawable and load into bitmap and decode the image and set into dynamic button..
note: here i dynamically created 100 buttons using for loop, that time, i need to load images.
i created successfully everything. when i run the program, i am getting memory error.
please help me solve this issue..
I Solved this problem using android:largeHeap="true" in application tag in AndroidManifest.xml
I have a background png in my Android application. I would like to support lots of displays, but I have this one obstacle - many displays have many resolutions and many ratios. I would like to make sure my background is displayed properly and make it more ellegant, than just creating 10+ cropped png files in Photoshop.
My idea would be - a fairly large picture imported in the project. The app would find out screen dimensions and simply say starting points(x,y) and ending points, that would "crop" the picture and display it without any deformations.
Is there a way of doing it?
I think bitmap.createBitmap() is the method your looking after. The method simply lets you cut out a defined portion of the bitmap.
I have an application in which i am setting the background of an image view.
If i keep my images in the re/drawable(s) folder, everything works fine but if i keep the same images in the sdcard and load from there to set the background then the dimensions of the image are different.
A similar question had been asked earlier but it is still unanswered. Could anyone shed some light on this topic.
if we place the images in res/drawable(s) folder then android chooses the appropriate image according to target device and scaling is also done by system if required. So if you are putting a image in sdcard then system does not do any scaling on image.
In my android project I need to get access for each separate pixel of JPEG image. Image created by built-in photo application. I try to convert JPEG into Bitmap class instance, but OutOfMemoryException was thrown. After searching info about this problem I have found the following solution: resize image! But quality of image is important in my project, and i can't resize it. Is there any way to get each-pixel access?
if your image is too big and the quality is important i suppose the best way is to use or create your own class to cut the image in zone (eg : 50*50 px) , there is several jpeg info class in the internet to help you understand how work jpeg files.
Have you tried BufferedImage ? (it's not in the sdk but maybe usable)
The nature of jpeg makes it very hard to get the value of a single pixel. The main reason is that the data is not byte aligned, another is that everything is encoded in blocks that can be of sizes 8x16, 16x8 and 8x8. Also, you need to handle subsampling of chroma values.
If the image contains restart markers, maybe you can skip into the image so you don't have to decode the whole image before getting the pixel value.