所以我正在调用使用 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 图像。但是,在模拟器中它显示为清晰的画面,想法?