How can I download scaled down version of an image? - java

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.

Related

Android - Optimizing application performance by image compression

I am working on an application that are loaded with large png images.
I started to optimize the app performance by reducing the size of each image to it's original size in phone.
I am using adobe photoshop . I was wondered how would be better to output the image file ? save it like normal or use "save for web" and compress it to PNG-8 or PNG-24 .
what do you advice ?
Try to use some of compress tools like http://tinypng.com or http://compressor.io, android studio has bundled some image optimization, if you want to know more watch Google I/O session about it.
http://youtu.be/r_LpCi6DQME

Multi-Resolution in Android?

I have been going through to achieve Multi-Resolution in android built in eclipse.
I have this app where i have used a lot of images, firstly the only limitation i have is size, i cannot exceed 5MB size for the app, surprisingly i was able to do this by just storing only in the xxhdpi folder, not all of the dpi folders, such as ldpi, mdpi and above xxhdpi devices dont support the app.
As you can see if i store all the folders with the respective images, it makes the app of size almost 15MB. I have read in forums that in cocos2dx there is a function to which only image is provided, which automatically scales the image with the device, and returns it to be set respectively,
i was wondering if there is a way to do this in android as well, thanx in advance
You'd better use SVG (vectorial images) files, through a 3rd party library.
SVGs are scalable (up or down, doesn't really matter) without loosing definition, due to their vectorial nature (it's just an xml file with geometrical definitions and color transitions).
This way, you'd have only 1 version of the graphical file and then only get the desired bitmap from it, with no ugly pixellation.
The most used libraries so far are android-svg and svg-android, primarily (there are a few other ones, and some variants to the proposed ones too).
Scaling is what they are meant to: you provide the SVG file (possibly in your raw or assets folder) and the needed dimensions (in pixels).
And get your bitmapped image out of the vectors.
Fantastic.
Our user Paul LeBeau is the author of AndroidSVG and he always lends a friendly support to whom needs a hand with his library.

Which is Faster regarding Android Images IO

Which is faster, to recieve images as JPG from server, and save it, then show it in a ListView or what ever
OR
receive images in an XML (as encoded String) from server, then decode it, then show it in a ListView (or even save it then show it from memory)
what is the best way (regarding performance) in transfering images FROM a server TO an android device
thanks in advance
That depends on where the limitation is. If the bandwidth of your connection is very small try to transfer as few bytes as possible. However, high compression usually costs more CPU, so if CPU power is limiting you it may be better to use a lower compression.
I am not sure what you mean by "receive images in an XML". Is it some vector format like SVG? That would normally be much smaller than a raster image (especially for large sizes).
To sum up, you will need to do some experiments to find out what works best in your case.
The best way is to get the image URL from the server and then download the image using some image managing library like https://github.com/nostra13/Android-Universal-Image-Loader or google's volley. These kind of libraries highly configurable and taking care of all the aspects of managing a bitmap.

Disable Java ImageIO Chroma Subsampling

I'm attempting to save a BufferedImage as JPEG using ImageIO. But even when saving using 100 quality, I am suffering quality loss due to Chroma SubSampling.
I have successfully fixed this issue by reverting to the older JAI libraries and explicitly setting the Horizontal and Vertical Subsampling to 1.
However a critical requirement is that I save the image as Progressive, which JAI doesn't seem to support.
Is there a way to disable sub-sampling using the newer ImageWriter?
Thanks in advance
If possible, I'd like to avoid ImageMagick
A reading of JPEG Metadata Format Specification and Usage Notes seems to suggest that this is possible by writing the image with a custom IIOMetadata.
A search on the internet brings up https://codereview.appspot.com/3082041/patch/204004/210007, which seems to use ImageIO in exactly this manner.
I haven't tried it, and have no idea if it actually works.

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.

Categories

Resources