的宽度从URL Image in MailiPhone - 我怎样才能得到高度的UIImage
我将图片添加到邮件视图。它会显示完整的图像。但我想计算,按比例改变图像的高度和宽度。
如何获得UIImage
的高度和宽度?
的宽度从URL Image in MailiPhone - 我怎样才能得到高度的UIImage
我将图片添加到邮件视图。它会显示完整的图像。但我想计算,按比例改变图像的高度和宽度。
如何获得UIImage
的高度和宽度?
let heightInPoints = image.size.height
let heightInPixels = heightInPoints * image.scale
let widthInPoints = image.size.width
let widthInPixels = widthInPoints * image.scale
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) ;
您不必创建另一个对象“UIImageView”,请参阅答案.... – Satyam 2011-12-15 10:03:34
以上所述的部分anwsers的,旋转设备时不能很好工作。
尝试:
CGRect imageContent = self.myUIImage.bounds;
CGFloat imageWidth = imageContent.size.width;
CGFloat imageHeight = imageContent.size.height;
UIImage *img = [UIImage imageNamed:@"logo.png"];
CGFloat width = img.size.width;
CGFloat height = img.size.height;
let imageView: UIImageView = //this is your existing imageView
let imageViewHeight: CGFloat = imageView.frame.height
let imageViewWidth: CGFloat = imageView.frame.width
可能是什么单位?像素还是点数? – byJeevan 2016-01-06 06:39:18
分。乘以scale属性来获取像素。 – rmooney 2016-06-28 14:50:12
这很奇怪。我用相机拍了一张照片,并假定它的高度>宽度。但宽度点是1280和高度720.他们有什么问题? – Henry 2016-10-31 00:28:37