iPhone - 我怎样才能获得高度和UIImage的宽度iPhone - 我怎样才能获得高度和

2019-05-13 08:54发布

从URL 中的邮件图片

我将图片添加到邮件视图。 它会显示完整的图像。 但我想计算,按比例改变图像的高度和宽度。

我怎样才能得到的高度和宽度UIImage

Answer 1:

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

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


Answer 2:

使用size属性的UIImage的实例。 请参阅文档了解更多详情。



Answer 3:

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

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


Answer 4:

一些anwsers的旋转设备时以上,不很好地工作。

尝试:

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


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


Answer 6:

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

let imageViewHeight: CGFloat = imageView.frame.height

let imageViewWidth: CGFloat = imageView.frame.width


文章来源: iphone - how can i get the height and width of uiimage