gpt4 book ai didi

iOS 调整大小并保存为调整后的图像

转载 作者:行者123 更新时间:2023-11-29 10:24:36 25 4
gpt4 key购买 nike

代码工作正常,但当我保存此图像时,它保存为原始大小。我怎样才能将其保存为缩放后的尺寸?

- (UIImage*) scaleImage:(UIImage*)image toSize:(CGSize)newSize {

CGSize scaledSize = newSize;
float scaleFactor = 1.0;
if( image.size.width > image.size.height ) {
scaleFactor = image.size.width / image.size.height;
scaledSize.width = newSize.width;
scaledSize.height = newSize.height / scaleFactor;
}
else {
scaleFactor = image.size.height / image.size.width;
scaledSize.height = newSize.height;
scaledSize.width = newSize.width / scaleFactor;
}

UIGraphicsBeginImageContextWithOptions( scaledSize, NO, 0.0 );
CGRect scaledImageRect = CGRectMake( 0.0, 0.0, scaledSize.width, scaledSize.height );
[image drawInRect:scaledImageRect];
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return scaledImage;
}

最佳答案

将 UIGraphicsBeginImageContextWithOptions 中的比例因子设置为 1.0。将其设置为 0.0 会将比例设置为设备的屏幕比例因子。

关于iOS 调整大小并保存为调整后的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33033613/

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