Base64 Image Size variation while saving - java

I am creating one application which downloads the images in base64 string format and save it in an image file while downloading data.
My application is available on two platforms: iOS/Android and PC/Mac
The problem is when I downloading the images and saving those on disk I am getting a size difference. In mobile it is downloading the exact size which I have uploaded but on my mac its size is greater than the actual size. Why the size of image in mac is greater than that of actual size downloaded?

in some of operating system maybe file size were difference, and its not problem if, for example your images view correctly.

I have observed that if I use
ByteArrayInputStream and Bufferred Image and ImageIO
class then it is saving the image in high resolution. Now I am using the class
FileOutputStream
to write the content in file. Its keeping the size same as uploaded.

Related

Load only some images from disk cache using Universal Image Loader

I am using the Universal Image Loader disk cache feature. I have restricted it to only cache images with the a maximum of 480x320 resolution. This works nicely, but when I tap those images to open the full size images, UIL loads the image from the disk cache and I see a stretched / distorted version of the small cached image.
I want to know how to tell UIL to load the images from disk cache but only for specific images. I have tried searching without luck.
Thanks.
It seems that the only answer to this is to create two instances of the ImageLoader. One with disk caching and one without it.

store bitmaps in an array?

Hi I am trying to download some images from the server, and I won't save them to the SD card because I want them to be gone when the application finishes. Therefore I want to store them in an array of bitmaps. Is this feasible? My largest image would be about 1000X1086 and there would be about 30-40 of them.
No. A bitmap is stored in memory as uncompressed bytes. A 1000x1086 full color bitmap is about 4MB. Most phones allow an app to use 16-40 MB max, and that includes built in resources. You're over by a factor of 10.
I'm using Universal Image Loader. You can save the images only in memory and clear it when you exit.
Here are all options for download images.
https://github.com/nostra13/Android-Universal-Image-Loader
You have an option... which ain't built in phone memory dependent...
You can save the images in the memory card and delete when the app finishes itself...
This is a really elegant method...

How can I download scaled down version of an image?

I need to download images that are very large 5mb+.
I am aware of scaling the image before displaying it to save phone memory but the problem of downloading a large image still remains.
How can I download, say, a 50% scaled down version of an image rather than downloading a full image then scaling it?
It must be supported by the server from which you download.
If the server is not yours, you need to look up that server's documentation (or reverse-engineer).
If the server is yours, it depends on the used technology. Look up an image manipulation library for that particular server-side technology you are using.
in case of imgur.com,
look here: http://api.imgur.com/
Imgur lets you make 500 calls per hour per IP, or 1000 if you are registered. Uploads count tenfold.
The metadata about an image is documented here: http://api.imgur.com/resources_anon#image_hash . Access either api.imgur.com/2/image/[hash].xml or api.imgur.com/2/image/[hash].json, and pick either image.links.small_square (90x90) or image.links.large_thumbnail (?x640) from the response. Note that imgur also generates thumbnails (160x160) for its home page. URLs for these seem to be i.imgur.com/[hash]b.jpg
The link to the large image is i.imgur.com/[hash].jpg, so if your link is http://i.imgur.com/xDpEF.jpg or http://imgur.com/xDpEF, then xDpEF is the hash you need.
It is NOT possible to download a scaled down version of some image when the web server does not provide a scaled down version.
You'll need to scale them in the web/on the server, where you host them. So the question is not java/android, but on the webserver, and depends on it.
You can't, unless your server supports scaling down the image before you download it. If the server doesn't have that option, your best option is to scale it down while you read the image from the stream, using BitmapFactory.Options inSampleSize.
Sir it is impossible because if you are downloading it from any server then server must have the scaled image in many forms like 50% scale or 25% scaled. So it is possible only when the server is maintained by you from where you are downloading the image and at backend you have provided some method to scale the image.
If you are downloading the image from any server then is is not possible to get scaled image from server without any backend procedure to scale image.
You will need to download the image to a file, then use BitmapFactory with BitmapFactory.Options to determine the size of the image. From the image size, calculate how much you want to scale it, and again use BitmapFactory (with Options) to load a scaled version of the image.
It depends on Server, Server should support scaling down the image.
In addition to the other answers there is one solution that may work without special software on server side;
If the images are stored on the server in JPEG format and uses the interlaced / progressive mode you would be able to download them partially for creating a thumb nail.
This special mode was designed to see a preview-image while it is still downloading. Compacting the preview image could result in an image that can be used as a thumbnail.
However I don't know a library that would support thumbnail loading this way.

Java Image resizing (3 sizes) upload each to Amazon S3

I'm using grails with jetS3t to upload an image to S3, this works fine.
But now I need to re-size the image (thumbnail, small and medium) and upload them all to S3.
So far I'm thinking about using ImageMagick, But don't know which is the best way to approach the resizing.
Should I:
Upload original to S3,
then re-size using the URL received from S3(another download), and upload the re-sized image to S3, (x3)
OR
Upload and use image bytes in memory, do all the resizing, upload the 3 re-sized photos and the original to S3
Depends on your quality requirements and memory availability.
If you want the resized images to be good quality then using ImageMagick is probably a good option but that requires the source image to be saved locally on disk. On the other hand, you won't need to store all images in memory. Im4Java worked very well for me as an interface to IM.
Using the Java Graphics package and BufferedImage class you can do an in-memory operation but this might not produce as good quality images.

java image compression and reduce bytes size

I developed a mass file up loader (a swing application) recently.One of the new requirements is to support uploading thousands of documents (GIF,JPG,PNG,DOCX,XLSX), each of these are like 3MB-10MB of size and we don't want to upload these huge files, we generally support TIFF files which has small byte size like 60KB-100KB. We are not concerned about the image quality, all we need to upload these docs for future reference. Right now I don't have any idea how to solve this problem, I started researching it. Please point me in right direction.
-PD
My first approach would be to convert them to pdf files. Everything that can be printed can be converted to pdf. This also allows for image compression. Tiff won't be a good idea for doc/xls I think, it might make them bigger.
a .doc or .xlsx can be gzipped very quickly for decent savings.
Images are more risky, depends on what the data is. Pictures of people? Pictures of text?

Categories

Resources