简体   繁体   English

iPhone图库应用程序将照片从4:3的宽高比裁剪为3:2,怎么办?

[英]iPhone gallery app crops photo to 3:2 from 4:3 aspect ratio, how?

The photo taken using the UIImagePickerController is of 4:3 aspect ratio. 使用UIImagePickerController拍摄的照片的纵横比为4:3。 However, the full screen aspect ratio is 3:2. 但是,全屏宽高比是3:2。 So the gallery app is doing some magic to show the photo as 3:2 aspect ratio. 因此,图库应用程序正在做一些魔术,以3:2的纵横比显示照片。 When you zoom out in the full screen view, the photo appears in 4:3 aspect ratio. 在全屏视图中缩小时,照片以4:3的纵横比显示。 Can anyone shed light on how it could be done? 任何人都可以阐明如何做到这一点吗? I've been breaking my head for the past two weeks on this. 在过去的两个星期里,我一直在努力。

Really appreciate the help!! 真的很感谢帮助!!

To fit a 4:3 image into a 3:2 space you can either match the height or match the width. 要将4:3的图像放入3:2的空间中,可以匹配高度或宽度。

If you were to match the height then you'd turn the 3 in 4:3 into the 2 in 3:2. 如果要与高度匹配,则可以将4:3中的3变成3:2中的2。 So you'd scale the entire image by 2/3. 因此,您将整个图像缩放了2/3。 Since you'd be scaling width and height by the same amount, the effective height after scaling would be the 4 from 4:3 scaled by 2/3, to give 8/3 — a bit less than three. 由于您将缩放宽度和高度相同的数量,因此缩放后的有效高度将是4:3中的4,再按2/3进行缩放,从而得到8/3-少于三。 You'd therefore not quite fill the screen. 因此,您可能无法完全填满屏幕。

Conversely, if you were to match the width then you'd turn the 4 in 4:3 into the 3 in 3:2. 相反,如果要匹配宽度,则将4:3中的4变成3:2中的3。 So you'd scale the entire image by 3/4. 因此,您将整个图像缩放了3/4。 Since you'd be scaling width and height by the same amount, the effective height at the end would be the 3 from 4:3 scaled by 3/4, to give 9/4 — a bit more than two. 由于您将宽度和高度按相同的比例缩放,因此最后的有效高度将是4:3中的3,再按3/4缩放,得到9/4 —略多于2。 You'll therefore slightly more than fill the screen. 因此,您将获得比填满整个屏幕略多的东西。

So that the photos app does is display pictures with an initial zoom so as to fit the width of the stored image to the width of the display. 照片应用程序要做的就是以初始缩放显示图片,以使存储的图像的宽度适合显示器的宽度。 If the stored image is 3264x2448 (which I think it is on the iPhone 4S and the 5) then on an iPhone 4s — using points rather than pixels — it's scaled by a ratio of 480/3264. 如果存储的图像是3264x2448(我认为它在iPhone 4S和5上),则在iPhone 4s(使用点而不是像素)上,缩放比例为480/3264。 If you work that out, it gives the image a final height of very close to 360pt, 40pt wider than the screen. 如果解决了这个问题,它将使图像的最终高度非常接近360pt,比屏幕宽40pt。

In terms of UIKit, that probably means putting a UIImage inside a UIScrollView and setting the initial value of zoomScale to 480/3264 (ie, approximately 0.15). 对于UIKit,这可能意味着将UIImage放在UIScrollView并将zoomScale的初始值设置为480/3264(即,大约0.15)。 The scroll view can help you with zooming in and out though there's still some manual work to be done — see eg this tutorial . 滚动视图可以帮助您放大和缩小,尽管仍然需要完成一些手动工作,请参见本教程 By setting a minimumZoomScale of 320/2448 (ie, approximately 0.13) you'll automatically get the behaviour where zooming out as far as you can go ends up showing the entire 4:3 image on screen. 通过将minimumZoomScale设置为320/2448(即大约0.13),您将自动获得尽可能缩小的行为,最终在屏幕上显示整个4:3图像。

not sure how you obtain your image, but you might have gotten one of the representations of the image. 不确定如何获取图像,但是您可能已经获得了图像的表示形式之一。 One of those representations is specifically for getting a quick fullScreen CGImage, an other will return the FullResolution. 这些表示之一专门用于获取快速的全屏CGImage,另一个表示将返回FullResolution。 FullScreen will be whatever is needed for the device (640x960 on iPhone4), Full resolution would be the 8MP picture. 全屏将是设备所需的任何内容(iPhone4上为640x960),全分辨率将是8MP图片。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM