2013-08-30 87 views
1

我陷入了一个问题,我正在创建图像,它的大小是350 * 350,但我想调整该图像的大小像32 * 32或16 * 16这样的小图像我正在这样做代码uiimage按比例调整大小因子


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(); 

但我没有得到期望的结果我的形象变得模糊,我尝试了许多,但事情没有工作好心帮我

+2

您正在调整大小约5%的东西,并将所有像素数据填入16x16图标。当然它会变得有点模糊。 – coneybeare

+0

to coneybeare的观点,大幅度缩小位图图像的大小会变得模糊,因为你失去了分辨率。如果您自己绘制图像,则可能会获得更好的重新绘制新尺寸的结果,而不是缩小更大的图像。 –

+0

请提供我一些代码,我正在为此工作,从最后4 5天,但没有得到我想要的结果我当前的图像是350 * 350,我想使它16 * 16 –

回答

0

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

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

试试看。

希望这会有所帮助。

+0

实际上它使模糊图像,但实际上我想要复制该图像在16 * 16,并使用该图像作为图释 –