gpt4 book ai didi

ios - 如何以编程方式调整图像像素大小

转载 作者:行者123 更新时间:2023-11-28 22:20:41 25 4
gpt4 key购买 nike

我正在使用 Facebook 创建应用程序。如果我正在尝试将照片上传到 Facebook 意味着我收到以下消息任何解决该问题的想法

“为 OG 操作提供的用户生成的照片在两个维度上必须至少为 480 像素”

最佳答案

我使用如下函数来获取任意大小的图像。原始图片应该比你想要的大。(ps:你可以尝试小图片)

+ (UIImage *)thumbnailWithImageWithoutScale:(UIImage *)image size:(CGSize)wantSize
{
UIImage * targetImage;
if (nil == image) {
targetImage = nil;
}else{
CGSize size = image.size;
CGRect rect;
if (wantSize.width/wantSize.height > size.width/size.height) {
rect.size.width = wantSize.height*size.width/size.height;
rect.size.height = wantSize.height;
rect.origin.x = (wantSize.width - rect.size.width)/2;
rect.origin.y = 0;
} else{
rect.size.width = wantSize.width;
rect.size.height = wantSize.width*size.height/size.width;
rect.origin.x = 0;
rect.origin.y = (wantSize.height - rect.size.height)/2;
}
UIGraphicsBeginImageContext(wantSize);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
UIRectFill(CGRectMake(0, 0, wantSize.width, wantSize.height));//clear background
[image drawInRect:rect];
targetImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
return targetImage;
}

关于ios - 如何以编程方式调整图像像素大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20495518/

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