Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UIScrollview更改UIButton';s缩小时的图像质量_Objective C_Ios_Xcode_Image_Ios5 - Fatal编程技术网

Objective c UIScrollview更改UIButton';s缩小时的图像质量

Objective c UIScrollview更改UIButton';s缩小时的图像质量,objective-c,ios,xcode,image,ios5,Objective C,Ios,Xcode,Image,Ios5,我有一个大的显示区域,可以平移和缩放以查看不同的对象。我遇到的问题是,如果缩小,PNG图像UIButton的质量会有所下降(但当我放大到100%时,它会恢复正常)。看起来图像几乎变得过锐化了。这是我不得不忍受的东西,还是有办法摆脱这种颗粒状边缘效应?顺便说一句,图像的纵横比始终是1:1。我可以使用ScrollViewDiEndZooming方法中的答案来解决这个问题。这是我的密码: 调整大小功能 - (UIImage *)resizeImage:(UIImage*)image newSize:(

我有一个大的显示区域,可以平移和缩放以查看不同的对象。我遇到的问题是,如果缩小,PNG图像UIButton的质量会有所下降(但当我放大到100%时,它会恢复正常)。看起来图像几乎变得过锐化了。这是我不得不忍受的东西,还是有办法摆脱这种颗粒状边缘效应?顺便说一句,图像的纵横比始终是1:1。

我可以使用ScrollViewDiEndZooming方法中的答案来解决这个问题。这是我的密码:

调整大小功能

- (UIImage *)resizeImage:(UIImage*)image newSize:(CGSize)newSize {
    CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));
    CGImageRef imageRef = image.CGImage;

    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0);
    CGContextRef context = UIGraphicsGetCurrentContext();

    // Set the quality level to use when rescaling
    CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
    CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, newSize.height);

    CGContextConcatCTM(context, flipVertical);  
    // Draw into the context; this scales the image
    CGContextDrawImage(context, newRect, imageRef);

    // Get the resized image from the context and a UIImage
    CGImageRef newImageRef = CGBitmapContextCreateImage(context);
    UIImage *newImage = [UIImage imageWithCGImage:newImageRef];

    CGImageRelease(newImageRef);
    UIGraphicsEndImageContext();    

    return newImage;
}
滚动查看方法 (Widget是一个UIViewController子类,它包含一个按钮和一个“widgetImage”,用于存储按钮应显示的图像的完整分辨率)

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{ 
    for(Widget *theWidget in widgets){
        UIImage *newScaledImage = [self resizeImage:theWidget.widgetImage newSize:CGSizeMake(theWidget.view.frame.size.width * scale, theWidget.view.frame.size.height * scale)];
        [theWidget.widgetButton setImage:newScaledImage forState:UIControlStateNormal];
        // theWidget.widgetButton.currentImage = newScaledImage;
    }
}