0

UIScrollView でズームを使用しているときに、png または jpg の品質を維持する方法について何かアドバイスはありますか? 写真を拡大するとピントがズレてしまう…

4

2 に答える 2

1

で次のコードを使用しますscrollViewDidEndZooming

- (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;
    }
于 2013-02-04T10:11:13.707 に答える
0
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
    CGSize nowSize = view.frame.size;
    if (nowSize.height >= self.myScrollView.frame.size.height)
        self.myScrollView.contentInset = UIEdgeInsetsZero;
    else {
        CGFloat delta = self.myScrollView.frame.size.height/2 - view.frame.size.height/2;
        self.myScrollView.contentInset = UIEdgeInsetsMake(delta, 0, delta, 0);
    }
}
于 2013-02-04T10:15:05.340 に答える