gpt4 book ai didi

ios - 调整 uiimage 大小后不给我确切的新大小

转载 作者:行者123 更新时间:2023-11-29 12:26:50 24 4
gpt4 key购买 nike

- (UIImage *)resizeImage:(UIImage*)image newSize:(CGSize)newSize {
CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height)); //CGSize is 51*51
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();
NSLog(@"size of resizeimage is %@",NSStringFromCGSize(newImage.size)); // here i get 102*102
return newImage;
}

我输入的cgsize是51*51,

调整大小后,当我检查尺寸时,它会给我 102*102。

为什么?请解决我的问题。

最佳答案

查看您的 UIGraphicsBeginImageContextWithOptions(newSize, NO, 0);,从 Apple 文档中,scale 参数表示:

The scale factor to apply to the bitmap. If you specify a value of 0.0, the scale factor is set to the scale factor of the device’s main screen.

所以如果是视网膜显示器,那是正常的。

关于ios - 调整 uiimage 大小后不给我确切的新大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28809355/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com