IOS - 下载图像从Parse.com后端 [英] IOS - Downloading Images From Parse.com Backend
问题描述
ORI有一个应用程序是一致的,从解析后端下载大的图像。在Android中,你可以下载图像,使用他们的URI流和特定的尺寸大小设置为我要下载的位图。通常这是使用BitmapFactory库完成,让我可以下载一个位图,这是一个缩小尺寸,从长期的加载时间救了我的应用程序。是否有一个等价的IOS平台上的这种方法吗?这是我目前在做什么,但是当我下载15全尺寸的图像,我得到了大量的加载时间:
orI have an app that is consistently downloading large images from a parse back-end. In android you can download the images as streams using their URI's and set a specific dimension size to the bitmap that I want to download. Usually this is done using the BitmapFactory libraries and allows me to download a bitmap that's of a scaled down size, saving my app from long loading times. Is there an equivalency to this method on the IOS platform? This is what I am currently doing, but when I download 15 full sized images I get a large amount of load time:
//where photoQuery is a Parse.com database query that returns the photo as the first object
PFObject *photoObject = [photoQuery getFirstObject];
PFFile *photoFile = (PFFile *)[photoObject objectForKey:@"fullSizedImage"];
UIImage *fullImage = [UIImage imageWithData:photoFile.getData];
是否类似BitmapFactory或这种常见的Android设计模式IOS支持的东西吗?
Does IOS support something similar to BitmapFactory or this common android design pattern?
推荐答案
PFFile
有一个名为法 - getDataInBackgroundWithBlock:
。可以使用这样的:
PFFile
has a method called – getDataInBackgroundWithBlock:
. Which can be used like this:
[photoFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if(!error) {
[imageView setImage:[UIImage imageWithData:data];
}
}
或者你可以使用一个叫做另一种方法 - getDataStreamInBackgroundWithBlock:
。它是如上所述一个相似的。所不同的是该块的第一个参数是一个 NSInputStream
Or you can use another method called - getDataStreamInBackgroundWithBlock:
. It is similar as the one above. The difference is the first parameter of the block is a NSInputStream
这篇关于IOS - 下载图像从Parse.com后端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!