Iphone 如何在小UIImageview上设置大UIImage
我正在使用大小为320X320的imagview来显示大图像(350 X 783) 在将大图像放入imageview时,图像看起来是压缩的,与高质量图像不同Iphone 如何在小UIImageview上设置大UIImage,iphone,Iphone,我正在使用大小为320X320的imagview来显示大图像(350 X 783) 在将大图像放入imageview时,图像看起来是压缩的,与高质量图像不同 我的问题是,如何才能使大图像变小,质量与原始图像一样好?您可以将图像视图设置为适当的内容模式,就像这样 imageView.contentMode = UIViewContentModeScaleAspectFit 你可以这样做 UIImage* sourceImage = "yourImage"; CGS
我的问题是,如何才能使大图像变小,质量与原始图像一样好?您可以将图像视图设置为适当的内容模式,就像这样
imageView.contentMode = UIViewContentModeScaleAspectFit
你可以这样做
UIImage* sourceImage = "yourImage";
CGSize newSize=CGSizeMake(80,80);
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
yourImageView.image=newImage;
谢谢,这个问题现在已经解决了,只是要注意,在处理多个大图像时,这并不能防止内存问题。
-(UIImage*)scaleToSize:(CGSize)size {
// Create a bitmap graphics context
// This will also set it as the current context
UIGraphicsBeginImageContext(size);
// Draw the scaled image in the current context
[self drawInRect:CGRectMake(0, 0, size.width, size.height)];
// Create a new image from current context
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
// Pop the current context from the stack
UIGraphicsEndImageContext();
// Return our new scaled image
return scaledImage;
}