的寬度從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