IOS - 从Parse.com后端下载图像

时间:2013-07-04 21:32:59

标签: android ios xcode uiimage parse-platform

或者我有一个应用程序,它始终从解析后端下载大图像。在android中,您可以使用URI将图像作为流下载,并将特定的尺寸大小设置为我要下载的位图。通常这是使用BitmapFactory库完成的,并允许我下载缩小尺寸的位图,从长时间加载时节省我的应用程序。在IOS平台上,这种方法是否相同?这就是我目前正在做的事情,但是当我下载15个全尺寸图像时,我会得到大量的加载时间:

//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];

IOS是否支持类似于BitmapFactory或这种常见的Android设计模式的东西?

2 个答案:

答案 0 :(得分:1)

PFFile有一个名为– getDataInBackgroundWithBlock:的方法。可以这样使用:

[photoFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
    if(!error) {
        [imageView setImage:[UIImage imageWithData:data];
    }
}

或者您可以使用另一种名为- getDataStreamInBackgroundWithBlock:的方法。它与上面的类似。不同之处在于块的第一个参数是NSInputStream

答案 1 :(得分:0)

PFImageView应该可以帮助您同步加载这些图像。您可以尝试使用Cloud Code缩略图像。

相关问题