计算iPhone中具有固定图像宽度的图像高度的标准比例? [英] Calculate the standard proportion of the image height with fixed image width in iPhone?

查看:75
本文介绍了计算iPhone中具有固定图像宽度的图像高度的标准比例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从iPhone 4G拍摄了图像,并将这些图像发布到服务器,之后,我获取了这些图像并显示在表格视图单元格中.更改图像高度时,我想显示图像的正确长宽比.

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.

在我的计算中,

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

请帮帮我.

谢谢!

推荐答案

为什么不将其放入UIImageView并将其contentMode设置为UIViewContentModeScaleAspectFit?

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

这篇关于计算iPhone中具有固定图像宽度的图像高度的标准比例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆