Calculate the standard proportion of the image height with fixed image width in iPhone?

喜欢而已 提交于 2020-02-06 05:23:10

问题


I have taken the image from the iPhone 4G and post those images to the server, after that i fetched those images and displayed in the table view cell. I want to display the correct aspect ratio of the image, when change the image height.

In my calculation,

  CGSize imageSize = image.size;

 CGFloat imageWidth = imageSize.width; (620) (In retina from iPhone 4G)

 CGFloat imageHeight = imageSize.height; (620)  (In retina from iPhone 4G)

 CGFloat aspectRatio = imageSize.width / imageSize.height; (620 / 620 = 1).

 CGFloat newImageWidth = 300.0f; (Fixed Width). 

 // Calculate new Image Height.

CGFloat newImageHeight = newImageWidth / aspectRatio; (300 / 1 = 300)

So, new image width / height.(300, 300).

And, Should i need to check the image is retina or not?

I don't know, whether the calculation is correct or not, so please guide me to achieve this. I want to know, standard procedure to find the height of the image with the fixed image width(Set the correct aspect ratio).

Please help me out.

Thanks!


回答1:


Why don't you just put it into a UIImageView and set its contentMode to UIViewContentModeScaleAspectFit?



来源:https://stackoverflow.com/questions/4613443/calculate-the-standard-proportion-of-the-image-height-with-fixed-image-width-in

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