2
我一直在尝试使用常用的方法调整图像大小。如果不使用这种方法,这里是需要一个图像的URL的代码。简单调整大小的图像
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
cell.imageView.image = img;
这工作正常。但是,当我尝试使用这种方法:
-(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
,并使用该称呼它:
UIImage *scaledImage = [self imageWithImage:img scaledToSize:CGSizeMake(10.0f,10.0f)];
然后投入我的表是这样的:
cell.imageView.image = scaledImage;
什么也不显示。有什么我在这里失踪?
它不应该是'的UIImage * scaledImage = [UIImage imageWithCGImage:cgScaledImage];'? – vikingosegundo 2010-11-17 00:51:04
你是对的,谢谢。 – Ryan 2010-11-17 00:59:40
谢谢..我在这一行上得到一个错误 [image.layer renderInContext:bitmapContextForCell]; 要求成员“层”的东西不是一个结构或联盟 – Allen 2010-11-17 03:44:22