I am making 1 android app where am capturing the image.I have used Media store also. Average image size is 128 KB.and I want it till 65-75 KB.
size of the file is always a trade of with quality - there are multiple ways to do so:
increase compression rate
decrease colors
decrease size
Related
I'm capturing an image using camera (And it is saved in the pictures folder). I want to resize it before convert it into String and upload it into a server. I have a constraint that the maximum file size should be about 850 kilobytes.
I have a knowledge about Bitmap.compress method which only reduces the image quality using a percentage. But the difficulty in that is that the different devices might produce images with different sizes. So I'm unable to use static percentage to reduce the size.
I have the image url and it can be converted to a Bitmap. Can I reduce the size of an image for any value under 850 kilobytes?
I am not familiar with android programming,
I wish to know if there is a way to set the video resolution when it is filmed inside an android application ?
Or, is there a way to reduce the resolution later.
We need to reduce the file size of the video that we capture.
Thanks
Shani
There are three things you can control to manage the resulting file size when recording video. All three are available as methods in MediaRecorder class:
Frame size (width x height). Use method setVideoSize(int width, int height). The smaller the frame size, the smaller the video file.
Encoding bit rate - this controls compression quality of each frame. Use method setVideoEncodingBitRate (int bitRate). Lower bit rate results in higher compression, which in turn leads to lower quality and lower video file size. This is only available from API level 8 and above.
Video "speed" - how many frames per second are captured. Use setVideoFrameRate (int rate) method. The lower the rate, the fewer frames you'll be capturing - resulting in a smaller video file size. This is only available from API level 11 and above. Remember though that for a smooth video you need at least 24 frames per second.
Have a look at the documentation for MediaRecorder` for more information.
I'm trying to write simple application where I can swipe between photos (like that standard gallery app on each device). Standard one demonstrates impressive performance - it displays next photo instantly while takes only about 15 MB of memory. It seems like it keeps next and previous images in memory so it doesn't have delay due to loading them from sd-card. I think that if the application keeps at least 3 Bitmap objects of such size in memory, it will take much more than 15 MB. So how it works? Don't use Bitmap or what? Thank you.
Remember that the bitmap on the screen might not be the size of your original file.
Take a 720p screen for example, a 4096*3072 picture will be decoded and re-sized to screen size.
Even the APP might be using ARGB8888 format to display a bitmap, the memory size is 1280*720*4 = 3686400 bytes, that is about 3.5M.
And if we use RGB565 format, the size will be half small then.
What's more, not all the picture is 'full screen'.
I'm making a game for Android and I'm using transparent PNG's. But does the transparent part take up large memory?
For example if I have a PNG that is 512*512 that is transparent, does that take up the same amount of RAM and or ROM as one with 256*246??
//Simon
The size depends entirely on the pictures resolution when beeing uncompressed in memory.
If you have pixel with transparency (an alpha-channel), you are most likely using ARGB8888 as the image format. With this each pixel takes 4 bytes in memory. Which means the 512x512 pixel image takes (512*512*4) bytes = 1 MB and the smaller on (256*246*4) bytes = 246 kB.
If the pixels are transparent (invisible) or not doesn't matter. Only resolution and internal format are relevant.
When your image is loaded into the memory it will be a bitmap, no matter what the original format on the disc was, so it really depends on what Config you load your image with.
If you load your image as ARGB_8888, every color component of every pixel of the image will take up one byte, i.e. the alpha (transparency) will take up one fourth of the total image memory and every pixel will be 4 bytes.
An image that is 512x512 pixels with transparency will take
about 1048 kB memory.
Without transparency it will be 786kB.
There isn't any RGB_888 colormode, the closest is RGB_565, which
would be 524kB.
Actually i am developing one application, where my requirement is like i have to scale large size images to some predefined size as per user selection. eg,Suppose i have an image which is of 1Mb and user select it to convert it into an image of size 100kb then i have to resize that image to 100kb.
last one day i am trying to achevive this with Bitmap APIs but i am not able to achieve the exact size what user want. Sometimes its very large sometimes very small. So please if anyone knows how to resize image in android to exact size(which is changing as per user selection).
Please help me out in this.
If only the file size matters, you will want to use an image file format that does not use compression. You should be able to take an image with attributes such as width, height, bit-depth, and so on and calculate the expected file size for such an image.
So, using such a file format you start with your original image and you have
File size = width x height x bit depth + metadata/overhead.
I assume you want to maintain the original aspect ratio also. In that case, you can probably just figure out the % reduction in file size from the current file size, and multiply the width and height by the same %. Scale your image using a bitmap image manipulation API and then save it. It should be close to the file size you are looking for.
Specific to the Android Bitmap api you can use getByteCount() to determine how many bytes the image currently takes up. You can also use getConfig() to determine how many bytes per pixel.
So, your final goal file size converted to bytes divided by the number of bytes per pixel, gives you the number of pixels you are allowed. Number of pixels allowed divided by the number of pixels in your current image will give you the scaling factor. Use the scaling factor and scale the image keeping the current aspect ratio and you should have a bitmap with a number of pixels close to your goal. Then save in a file format that does not use compression.