UIImagePickerController cameraViewTransform acts differently in iOS 4

可紊 提交于 2019-11-30 09:45:32
Ela

ios 4.0 Magic number 1936/320= 6.05 , 2592/6.05 = 428 , 480-428 = 52 52/(428/2)=0.24299 +1=1.24299

ios 3.0 Magic number 1536/320=4.8 2048/4.8=427 480-427=53 53/427=0.121412 +1=1.12412

That is the relationship cameraresolution-screenresolution

For iOS 3.0 the cameraViewTransform is applied from the top so you have to use all the height. But in iOS4 it is applied from the center of the frame so you have to use the half of the height. And you have to move the frame down (52/2) to leave the frame in the center.

I am not sure about iOS 3.0 but for iOS 4.0 the cameraViewTransform is applied from the center of the frame. You can verify this by first applying a translation transform.

CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 27.0);
imagePickerController.cameraViewTransform = translate;

You can see that this moves the view to the center. Next apply the scaling transform and you will see that it fills the screen.

CGAffineTransform scale = CGAffineTransformScale(translate, 1.125, 1.125);
imagePickerController.cameraViewTransform = scale;

If the scaling transform alone works for iOS 3 and company then the transform is applied to the a different anchor point like center top. You should always scale linearly in both directions or your image will be skewed.

CGAffineTransformMakeTranslation will not work directly on cameraViewTransform. So, use CGAffineTransformScale to apply CGAffineTransformMakeTranslation.

float yOffset = 44.0;
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, yOffset);
self.cameraFeed.cameraViewTransform = CGAffineTransformScale(translate, 1, 1);

I'm finding the new scale transform for the iPhone 4 to be ~1.25 (instead of ~1.12).

I spent a few minutes trying to figure out where these magic numbers come from - I assume there's some sort of relationship between the screen resolution & the camera resolution, but I couldn't figure it out in a hurry...

If someone does, please post an answer - I hate magic numbers.

FYI the camera res of the iPhone 4 is 2592x1936, while the iPhone 3GS is 2048x1536.

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