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

三世轮回 提交于 2019-11-26 15:06:00

问题


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.

How can I get the height and width of UIImage?


回答1:


let heightInPoints = image.size.height
let heightInPixels = heightInPoints * image.scale

let widthInPoints = image.size.width
let widthInPixels = widthInPoints * image.scale



回答2:


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




回答3:


UIImage *img = [UIImage imageNamed:@"logo.png"];

CGFloat width = img.size.width;
CGFloat height = img.size.height;



回答4:


Some of the anwsers above, don't work well when rotating device.

Try:

CGRect imageContent = self.myUIImage.bounds;
CGFloat imageWidth = imageContent.size.width;
CGFloat imageHeight = imageContent.size.height;



回答5:


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) ;



回答6:


    import func AVFoundation.AVMakeRect

    let imageRect = AVMakeRect(aspectRatio: self.image!.size, insideRect: self.bounds)

    x = imageRect.minX

    y = imageRect.minY



回答7:


let imageView: UIImageView = //this is your existing imageView

let imageViewHeight: CGFloat = imageView.frame.height

let imageViewWidth: CGFloat = imageView.frame.width


来源:https://stackoverflow.com/questions/5249664/iphone-how-can-i-get-the-height-and-width-of-uiimage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!