简体   繁体   中英

is it possible to download image at low resolution from url?

i am trying to load images from URL to UIIMageView . it works fine, but i want to download the images at a lower resolution/size because its taking too long to load.

i have tried to use AFNetworking+UIImage class but the performance are the same.

    [iv setImageWithURL:[NSURL URLWithString:@"http://cegamers.com/wp-content/uploads/2011/06/automaton.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder-avatar"]];

anyone know how a library or some kind of way for this?

Generally you can't do it without server-side help. Usually you'd rely on the server generating thumbnails for you. There are image conversion proxy servers that will download the full image server-side, and serve a resized version to you.

Without any sort of server-side resizing, the options are limited and not very good.

If the image is in progressive/interlaced format then you can download only part of the file, but that will be a low-quality approximation.

Unfortunately you can't know how much data you'll need in advance, so your best bet is to either request entire image and close the TCP/IP connection when you see you've got enough data (hopefully [NSURLConnection cancel] does that) .

Or you could download some arbitrary small amount of data using HTTP Range request and then estimate how much more you need to download (it might save some bandwidth, but it will cost you latency).

I'm not aware of anything in iOS SDK that would let you inspect how many progressive scans of a partially-downloaded JPEG file you've got, so you might need to get your hands dirty with libjpeg or your own JPEG parsing.

But really it'd be easier if you could download entire image server-side and generate a proper thumbnail for it.

Yes. If you simply add 's' to the end of the img_hash in any direct image link on imgur, then you get the small square version of it.

http://i.imgur.com/DkDdK.jpg <--- Direct link
http://i.imgur.com/DkDdKs.jpg <--- Small square version. Notice the extra s

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM