I encountered a problem with uploading an image.
It seems that i can't display PNG images that exceeds 2800x2800 pixel after upload.
But I can display jpeg images that exceeds those resolutions.
Is there a way to modify the maximum resolution for png images?
Or is there a way to prevent uploading a high resolution png image?
I'm using file.browse() to upload image.
see Flash Player 10 size limits for SWF, bitmap files:
To access the increased bitmap size limits, it's required that the
compiled is SWF version 10 or later. Content compiled to a SWF 9
target and running in Flash Player 10 or later are still subject to
Flash Player 9 limits (2880 x 2880 pixels). The largest square bitmap
allowed is 4,095 x 4,095 pixels. ...
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.
I decided to investigate my app's memory usage and I looked at Android Studio's Memory Monitor and my memory usage was around 68 MB. It looks too high to me.
I opened memory allocator and started tracking from the beginning of the application. I saw that there is a 49 MB allocation of a NonMovableArray, which is a Bitmap.
I debugged the application and found out that it was the background I was using. The lines below are from PhoneWindow.java file, that's where Android assigns the background to the screen I believe. The background object had a size of 49 MB and 2625x4669 resolution.
I have no overdraw in my app, and I have a single background that is applied to entire theme.
I have a background drawable in drawable folder in JPG format with 750x1,334 resolution.
PhoneWindow.java
if (mBackgroundResource != 0) {
background = getContext().getDrawable(mBackgroundResource);
} else {
background = mBackgroundDrawable;
}
I am testing this on a Motorola Nexus 6 device which has 560 density with a resolution of 1440 x 2560.
There are two points I don't understand.
If the device has a resolution of 1440x2560, why would my background get converted to 2625x4669?
Even if this conversion is the best scenario for the app, how come a 160 KB file would end up being 49 MB?
If you guys can explain this to me that would be great. Thanks!
If the device has a resolution of 1440x2560, why would my background get converted to 2625x4669?
You put the image in res/drawable/. This is not a good choice, as that is a synonym for res/drawable-mdpi/. Hence, Android is resampling your image, thinking that you were aiming for -mdpi devices (~160dpi), so the image is about the same physical size on the Nexus 6 (3.5x the density).
Whether res/drawable-nodpi/ or res/drawable-anydpi/ is the right choice depends a bit on your alternative versions of this resource, though either will probably work.
how come a 160 KB file would end up being 49 MB?
The image takes up 160KB on disk. The memory footprint is the decoded image. That will be the image resolution (post-resampling) times 4 bytes/pixel for ARGB_8888 images. 2625x4669x4 ~= 49MB.
The default and highest quality configuration for a Bitmap is ARGB_8888, which will use 4 bytes per pixel. Since your image is being scaled to 2625*4669, that's:
2625*4669*4 bytes = 49024500 bytes
http://developer.android.com/reference/android/graphics/Bitmap.Config.html
I'm not sure about the resolution differences, but the difference between the used memory and the size of the file is because an image in the JPG format (as many other formats) is compressed (see the wiki for how). When you then load it into memory, it is no longer compressed, as it's used to draw every single pixel on the screen.
I am trying to create a screenshoot of a zone of my screen
I did some test and for JPG file it always create a 96 dpi resolution image.
I tried using the technique described in How to set DPI information in an image? but it seems to only change the metadata of the image.
Thanks for help
edit 1 : so I want to create a screenshot at a resolution higher than what my display is using. As #Toam said, the display is actually 96 DPI
Why the same width&height images don't have the same sizes? As I understand they both have the same amount of pixels, don't they? So why can one weigh more than the other?
In the Bitmap format (files with extension .bmp):
The header size could be different. (In header, the file format, image size, image color type, and such kind of additional information is stored.)
The size for one pixel could be different. 1 bit/pixel for black/white images. 8 bit/pixel for at-most-256-color images. 24 bit/pixel for standard images. 32 bit/pixel for images with transparency information (Although .bmp files nearly-never have transparency information, .png files often have.).
In the JPEG, PNG, or other format: 1, 2 from the above are also applied. Additionaly,
The image is compressed and stored (for example, jpg, png, ...).
They may have layer or animation information (for example, gif).
Because pixels can have different size
It can be 1bit(black&white),8bit,16bit,24bit,32bit and even more
So,two images with same width(480px) and height(640px) but with with different pixel size have different size.
i.e 480 X 640 X 32bit pixel != 480 X 640 X 1bit pixel
I'm using the itext PDF library to build a very image-intensive PDF document in Java. Each page has a dozen images on it. The original source images are very high resolution, and I'm using scaleToFit to render the image to the size I need.
The problem I have is that the PDF document is still very large. My understanding is that the entire original high resolution image is being included, and the scaling I'm using only affects the actual rendering, not the size of the image that's included in the file.
I've verified this by removing the scaling — the pages were rendered with the high resolution images overlapping each other and the edge of pages, and the PDF was the same size as when the scaling was in place.
So, here's the question — how can I reduce the size of the PDF file by scaling down each image? If I lose a little bit of image quality that's ok. Rescaling the source images manually will be difficult.
So I've found a way to do it. I now load the image into a BufferedImage, and then scale that using the hints found here: how do I scale a BufferedImage.
This gives me a BufferedImage — I then convert this into an iText image using
Image returnedImage = Image.getInstance ( pcb, bufferedImage, quality );
Where quality is currently 0.6. That's acceptable for the work I'm doing.