【发布时间】:2011-11-30 18:17:37
【问题描述】:
所以我正在调用使用 Nimbus 的 NINetworkImageView 对象从照片服务器中提取图像。我需要检查返回的对象是否有效。如果无效,则方法
- (void) networkImageView:(NINetworkImageView *) imageView didLoadImage:(UIImage *) image {
返回一个透明的 UIImage 对象。我认为该方法返回给我一个带有清晰像素的 jpg 图像,这导致了我的问题。我尝试了以下检查以查看图像是否透明但没有运气(以下所有尝试都发生在上述方法的范围内):
尝试 1 失败:
UIImageView *tempView = [[UIImageView alloc] initWithImage:image];
if(tempView.alpha != 0.0f)
{
//the image is a valid (nonclear) image
}
else
{
//the image is invalid (clear)
}
尝试 2 失败:
CGImageRef cgref = [[UIImage alloc] CGImage];
CIImage *cim = [[UIImage alloc] CIImage];
if(!([image CIImage] == cim && [image CGImage] == cgref))
{
//the image is a valid (nonclear) image
}
else
{
//the image is invalid (clear)
}
尝试 3 失败:
if(image)
{
//the image is a valid (nonclear) image
}
else
{
//the image is invalid (clear)
}
尝试 4 失败:
CGImageRef cgref = [image CGImage];
CIImage *cim = [image CIImage];
if(cim == nil && cgref == NULL)
{
//the image is invalid (clear)
}
else
{
//the image is a valid (nonclear) image
}
编辑
我能够从模拟器中提取“无效图像”。 networkimageview 方法返回一个完全白色的 jpg 图像。但是,在模拟器中它显示为清晰的图片,想法?
【问题讨论】:
-
无效是什么意思? Nimbus 文档说还有委托方法
networkImageViewDidFailLoad:- 你的情况是这样吗?或者你的意思是返回了数据,但是图片加载失败。在这种情况下,我希望image是nil或image.size是CGSizeZero。 -
对不起,我的意思是如果图像是空白的,它是“无效的”。图像加载得很好,但图像很清晰。使用@beryllium 指令我能够检查下载的图像。这是一张没有 Alpha 通道的 JPG 图像,但由于某种原因,它显示为空白图像。
标签: iphone ios uiimage nimbus-ios