简体   繁体   English

UIImage imageWithData如何查找图像大小和调整大小比例

[英]UIImage imageWithData how to find image size and resize ratio

I have two UIImages that need to be relative to each other, however I dont know how to calculate tha ration of the UIImage size that I have set to the actual size of the image I am receiving in Base64 data. 我有两个需要彼此相对的UIImage,但是我不知道如何计算已设置为我在Base64数据中接收的图像的实际大小的UIImage大小。

Currently I am doing this with no calculation of the change in size of the original imageview and currently the profileImageView is much much bigger than it needs to be as its not dynamic. 目前,我是在不计算原始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];
    }

This works by putting everything in the correct position its just that the ratio of image ones adjustment is not the same as the profileImage, and I need to get them the same. 这是通过将所有内容放置在正确的位置来实现的,只是图像调整比例与profileImage不同,我需要使它们相同。

UIImage has a size property, which is a CGSize struct. UIImage具有size属性,它是CGSize结构。 That should give you the width and height of the image itself. 那应该给你图像本身的宽度和高度。

It also has two other properties called scale and resizingMode , and you may want to check those out too. 它还有两个其他属性,分别称为scaleresizingMode ,您可能也想检查一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM