I am trying to do the following steps -
Read an scaled image from assets and display in an imageview. - Successful
Modify the image - Successful
Save it to the SD card.- Not successful.
The resolution of the image is 4608 x 3456 with 300 ppi.
Since i was getting an out of memory exception on reading the image, i have scaled down the image to 800 * 800 while reading it using BitmapFactory.Options .
Now when i modify and save the image to SD card , the resolution of the image is 800 * 800 .
I want to get the exact same resolution as the resolution of the image in assets.
How to achieve this ?
Any help will be highly appreciated.
This SO helped me to create Image of required resolution i tried creating full hd image(1920×1080) i'm not sure whether you can create 4608 x 3456 resolution image.
Related
I got a new requirement to present an image instead of an error text if there is no items to show and the image almost have 440 KB (PNG) in size that given by my UI/UX designer. So I don't think it's fair to use it straightforward. As it's a transparent background image it's not possible to reduce the size by converting into JPG format. I got 4 resolutions of the image for placing it in different resolution resource folder. but if I keep all of them in my APK, that itself take near 1 MB, So I had taken only one image from drawable-xhdpi folder and kept in drawable-nodpi. Okay, So my queries as follows
1) How can I efficiently use that image ?
2) Any worries if I use JPG icons as substitute of PNG ?
3) What about keeping images like these only in drawable-nodpi and setting size in different dimension file ?
1) Convert the PNG to WebP if you only need to support API level 13+, otherwise use ZopfliPNG to optimize your PNG.
2) JPG does not support alpha channel and it's lossy.
3) Just put it in drawable-xhdpi and let Android scale the image for you. Only put images in drawable-nodpi if you don't want the image to be scaled.
I calculate inSampleSize to use Bitmap decode method to resize large png files.
When creating a this new bitmap and Log info it's width and height with .getWidth() and .getHeight(), its pixels count has grown by 3 relative to its original size.
code: from line 121-204
https://github.com/abisai1221/android-bitmaps/blob/master/png%20to%20bmp
all help is greatly appreciated.
I would bet on screen density being applied. When you load bitmaps from resources, you have to put them in right drawable folders, because Android will automatically scale them to match your phone's screen density. Each folder should contain only images for one specific density. For example, if you have a high density screen in your phone, you should put images in drawable-hdpi folder to get them without scaling. If you're getting 3 times larger images, you probably have a very dense screen, like Nexus 5 or recent Galaxy S phone. To disable scaling, put images in drawable-nodpi folder.
I saw another post of resizing issues and came across the ".inScaled" field of BitmapFactory.options.
This executes by default to scale bitmap to target density.
I set this field to false to prevent it from executing and the images come out perfectly, tho Im still confused as to why it scales the image by a factor of 3.
I am accessing images from android resources folder.
i am using asynctask to load images.
On first time i used images with resolution of 1024*768 the app opens and one by one image is shown into imageview.
on second time,
For experiment i used images with resoltion 1920*1080 the app is giving runtime error and force closed.
The same happens with image resoltion of 1280*720.
but it perfactly runs with 1024*768 resolution
why this happens????
i m not posting code cause it doesn't seem to have programatical issue.
Simply you got Out Of Memory exception because your image size is large, consider this calculation:
In order to show each pixel in ARGB_8888 we use 4 bytes so:
your first image: 1024 * 768 * 4 = 2MB
your second image: 1920 * 1080* 4 = 6MB
your third image: 1280 * 720 * 4 = 3MB
I do not know how many images you are loading to your RAM but your RAM is limited and it is at least 16MB so with other 4-5 images you will have no RAM to other objects. look at
Loading Large Bitmaps Efficiently to solve your issue.
I've got a program which is loading resources from the resource file (by setting android:src="#drawable/image" in the layout file.
The image is 800 x 1280 pixels. When the program runs it allocates 16,384,000 bytes on the heap which is 16 BYTES per pixel.
I assumed that it should default to RGB8888 which only uses 4 bytes per pixel. Anyone know how I can change this to use less memory?
Your images could be stored in an inappropiate folder. If you have high resolution images in a low resolution folder, let's say, the images are 800 x 1280 and you're storing it in drawable or drawable-hdpi, Android will scale them up to match xhdpi (although they are already in xhdpi, so to say). The scaled image occupies more memory.
Solution, put them in drawable-xhdpi.
you can import them using BitmapFactory, Options, and inSampleSize to reduce the memory footprint.
Also, that seems like a very high res image to display on a mobile screen so you could also reduce the size?
Check the documentation about bytes per pixel: http://developer.android.com/reference/android/graphics/Bitmap.Config.html
You can try using Color.RGB_565, but the image may lose quality.
i am going to publish my android app on android market i fileed all the information as screen shot ,application icon 0f 512*512 size every thing is ok and when i click on publish button following below error is coming for screen shot..
Screenshots:
320 x 480, 480 x 800, 480 x 854,
1280 x 720, 1280 x 800
24 bit PNG or JPEG (no alpha)
Full bleed, no border in art
You may upload screenshots in landscape orientation. The thumbnails will appear to be rotated, but the actual images and their orientations will be preserved.
and display a message that "please correct the error below and try to save again"
i used 480*800 size of image of type .png then what is the problem and when i attaching the screen shot and uploading it it uploaded successful and when i deleting attached screen shot it is not deleting...i upload 4 screen shot..
I had the same problem, and as with Sarwar Erfan above I converted them to JPG (100% but dont know if that's significant) and it cleared the errors