Android ImageSize Increases after downloading | Picasso - android

I have an image stored on my server whose size is 89kb.
https://s3-ap-southeast-1.amazonaws.com/images.crownit.in/emailer/push_banner_tambola_01072017_v2.jpg
However, after I download the bitmap using Picasso, The byteCount comes out to be 2 MB.
double lengthbmp = bitmap.getByteCount(); //1920000 Bytes
Is this anything to do with the resolution of the image?

The reason for the size change is due to a change in file format. The file is hosted as a JPEG, however you are converting it to a bitmap in your application. I converted the file using photoshop to give an example of the difference in file size based on format:
In terms of network load you will still only move the 89kb, as the file only increases in size when converted to bitmap in your application.
If you really want to maintain the JPG format follow the answer given in the following post: How to display image from URL on Android

Related

How to compress GIF image before uploading to server in android?

how to compress GIF image before upload it to the server ?, i tried some android libraries to compress gif image but it convert it to png image. is there any way to compress gif image ?
im using a bitmap in my projects.
Bitmap
Example code:
ImageView carView = (ImageView) v.findViewById(R.id.imagen_cr7);
byte[] decodedString = Base64.decode(picture, Base64.NO_WRAP);
InputStream input=new ByteArrayInputStream(decodedString);
Bitmap ext_pic = BitmapFactory.decodeStream(input);
carView.setImageBitmap(ext_pic);
GIF is a lossless image compression format: it is set up to reproduce the image exactly.
As a consequence, there is no "image quality" slider (as in JPEG encoders); although a GIF will likely be much smaller than an uncompressed format (such as many camera RAW or common TIFF options), there is a limit to how far it can go.
Also, you should know that GIF is limited to 8 bits per pixel (so it is most appropriate for line art, not photo-like images). If your source image is a full 24 bits, it must be dithered to fit into a 256-entry color palette. So, although the GIF format itself is lossless, the image processing required to use it in the first place may be lossy.
There are a number of things you can do to reduce the size of your image file:
You can choose a lossy format (such as JPEG), which will allow much greater compression. Note that JPEG works well on photo-like images, but not so well on line art. Also, (although your question explicitly rejects it) PNG may be a reasonable option, as it (losslessly) supports 24-bpp images.
As mentioned in a comment, you can try reducing the resolution of your image, and shipping the reduced version. If you can't generate a smaller image to start with, image resizing typically works well on photo-like images, and there are nonlinear resizing filters available that are specifically intended to handle line art.
If a full-resolution GIF is mandatory for your application, you may be able to generate an image that is more compressible by the GIF format. GIF compresses solid blocks of color extremely well -- but does less well on dithered or noisy images (such as you might get from converting a 24-bpp image to GIF format).
Since you have not given any information on your requirements (what kind of image you have, where you got it, and what you need it for), it is hard to come up with specific advice.
However, there is a good chance that your GIF has far more resolution than you need for your particular application (leading to option #2).

Android - Resize camera image in kilobytes

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?

Android stream multiple bitmap tiles to single jpeg file

I am developing an image manipulation application which has to be able to work on large images e.g. those taken by a camera, the approach I'm taking is to split the source image into multiple suitably sized tiles so that the tiles can be loaded individually into memory as a Bitmap without exceeding the dreaded VM limit, next image manipulation is performed on a tile by tile basis, this is all well and good but until I want to stitch these tiles back to a final jpeg image.
I'm looking for a built in sdk api or free ware solution that can perform the following:
Open jpeg output file as output stream
Stream RGB pixels from bitmap (tile 1) to jpeg output stream
Stream RGB pixels from bitmap (tile 2) to jpeg output stream
etc.. for all tiles
Close jpeg output stream
Any ideas or pointers other than writing my own jpeg encoder?
What about this:
FileOutputStream outFile = new FileOutputStream(output_file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outFile);
outFile.flush();
outFile.close();
You can adjust the quality setting (100). See the docs
You'll still need to decide how to slice it. But if you're taking the image on the device, why would it be a problem loading the whole image if it didn't cause a memory problem in the first place?
Stitching Tiles back together: Here's one simple approach used by slippy maps the I know works.
Cut tiles in standard size (say 256x256)
Assign each tile an x,y value - this could be a directory structure or filename convention: i.e. "0_0.jpg"
Tile names (numbers) are related to their top/left pixel position.
Each tile number can be calculated by the following:
tileX = floor(pixelX / 256)
tileY = floor(pixelY / 256)
So the tile at pixels 0,0 = tile (0,0), the tile at pixels 256,0 is tile (1,0), etc...
Your stitching approach has two major issues and will ultimately fail. If you ask the system to decode a JPEG file in parts, the decode time will end up being close to N times longer (N = number of parts). The next problem is that when trying to save the image you will run out of memory. JPEG images need to be compressed in one shot. If your entire uncompressed image can't fit in memory, then you won't be able to use the technique you're using.
The hard truth is that, with Android as it is currently designed, you must use native code to hold on to the bitmap in order to manage an image larger than the VM memory limit. It's not that difficult, but it does require a re-design of your app.

Show Tiff format image in Android

I am using ImageView to showing the .tiff formatted image, but I am getting error of NullPointerException.
I am converting the image file into byte array and then setting it in ImageView.
How can I show this tiff file?
You cannot set the tiff image on a ImageView in android directly. http://code.google.com/p/tiffonandroid/source/browse/ this is a sample tiffviewer. This might help you
Tiff has images stored as rows of bytes starting at defined offsets. So you can easily retrieve single rows to build the full image.
If you open any tif file in hex editor you will see that first 4 bytes mark tiff by code. And next 4 bytes give offset for metadata about tif image.
Use random access file to open image tif file, then seek the offset and you land into metadata space.From here you can pick offset of required image rows. Then go and get it..
If we needed full load of image like jpeg or BMP, then collect and combine all these rows after decompression, if any. Then you will get the full image

Access to separate pixel of JPEG image in Android

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.

Categories

Resources