gpt4 book ai didi

ios - UIImage imageWithData 如何找到图像大小和调整比例

转载 作者:行者123 更新时间:2023-11-29 02:41:26 25 4
gpt4 key购买 nike

我有两个需要相互关联的 UIImage,但是我不知道如何计算我设置的 UIImage 大小与我在 Base64 数据中接收的图像的实际大小的比例。

目前我这样做时没有计算原始 imageview 的大小变化,目前 profileImageView 比它需要的要大得多,因为它不是动态的。

if ([recivedRquestType isEqualToString:@"FaceBlank"]) {
FaceBlankImage = [UIImage imageWithData:data];

[imageView removeFromSuperview];
imageView = nil;
imageView = [[UIImageView alloc] initWithImage:FaceBlankImage];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.frame = CGRectMake(0.0, 70.0, ScreenWidth, (ScreenHeight/2)-75);

[self.view addSubview:imageView];
// call profile
[engineRequests GetImageK:currProfile RequestType:@"Profile" NavController:self.navigationController];

} else if ([recivedRquestType isEqualToString:@"Profile"]) {
profileImage = [UIImage imageWithData:data];

[profileImageView removeFromSuperview];
profileImageView = nil;
profileImageView = [[UIImageView alloc] initWithImage:profileImage];
profileImageView.contentMode = UIViewContentModeScaleAspectFit;
profileImageView.frame = CGRectMake(0.0, (ScreenHeight/2)-10, ScreenWidth/2, 50.0);

[self.view addSubview:profileImageView];
}

这是通过将所有内容都放在正确的位置来实现的,只是图像调整的比例与 profileImage 不同,我需要让它们相同。

最佳答案

UIImage 有一个 size 属性,它是一个 CGSize 结构。这应该会为您提供图像本身的宽度和高度。

它还有另外两个属性,称为 scaleresizingMode,您可能也想检查一下。

关于ios - UIImage imageWithData 如何找到图像大小和调整比例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25735447/

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