iphone - how can i get the height and width of uiimage

后端 未结 8 1724
温柔的废话
温柔的废话 2020-11-30 18:03

From the URL Image in Mail

I\'m adding image to mail view. It will show full image. But I want to calculate, proportionally change the height and width of the image.

相关标签:
8条回答
  • 2020-11-30 18:35
    let heightInPoints = image.size.height
    let heightInPixels = heightInPoints * image.scale
    
    let widthInPoints = image.size.width
    let widthInPixels = widthInPoints * image.scale
    
    0 讨论(0)
  • 2020-11-30 18:38
    UIImage *img = [UIImage imageNamed:@"logo.png"];
    
    CGFloat width = img.size.width;
    CGFloat height = img.size.height;
    
    0 讨论(0)
  • 2020-11-30 18:40
        import func AVFoundation.AVMakeRect
    
        let imageRect = AVMakeRect(aspectRatio: self.image!.size, insideRect: self.bounds)
    
        x = imageRect.minX
    
        y = imageRect.minY
    
    0 讨论(0)
  • 2020-11-30 18:42

    Use the size property on the UIImage instance. See the documentation for more details.

    0 讨论(0)
  • 2020-11-30 18:43

    There are a lot of helpful solutions out there, but there is no simplified way with extension. Here is the code to solve the issue with an extension:

    extension UIImage {
    
        var getWidth: CGFloat {
            get {
                let width = self.size.width
                return width
            }
        }
    
        var getHeight: CGFloat {
            get {
                let height = self.size.height
                return height
            }
        }
    }
    
    0 讨论(0)
  • 2020-11-30 18:50
    UIImageView *imageView = [[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"MyImage.png"]]autorelease];
    
    NSLog(@"Size of my Image => %f, %f ", [[imageView image] size].width, [[imageView image] size].height) ;
    
    0 讨论(0)
提交回复
热议问题