1

我陷入了一个问题,我正在创建图像,它的大小约为 350 * 350,但我想将该图像调整为 32 * 32 或 16 * 16 之类的小图像,我正在使用此代码执行此操作


UIImage *scaledImage=img_Clip;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(16, 16),NO,0.0);
// Turn off interpolation to keep the scaled image from being blurred.
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);

[scaledImage drawInRect:CGRectMake(0, 0, 16, 16)];  // scales image to rect
UIImage *resImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

但是我没有得到想要的结果我的图像变得模糊我尝试了很多东西但没有任何工作请帮助我

4

1 回答 1

0

您可以做的是UIImageView使用未缩放的创建一个UIImage,然后更改图像视图的 frame.size。这将自动缩小您的图像。希望不会使您的图像模糊。

UIImageView *imageView = [UIImageView initWithImage:unscaledImage];
imageView.frame = CGRectMake(0,0,16,16); // change the size of the image view

试试看。

希望这可以帮助。

于 2013-08-30T22:32:31.453 回答