iPhone如何使用私有库PhotoLibrary中的类PLCameraController

本文介绍了如何使用Apple的私有框架PLCameraController控制iPhone的内置相机,并获取视频预览流。通过简单的步骤,可以实现摄像头预览功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

iPhone:Using PLCameraController


The PLCameraController class is for controlling iPhone's built-in camera and one of Apple's private frameworks. If you want to get the preview of incoming video stream from the camera, it is quite easy to do it. Here are steps to do it. 

1. Get the header of PLCameraController. This can be obtained by dumping iPhone OS frame works by using class-dump-X, or you can download it from somewhere.  

2. Add the PhotoLibrary framework from the SDK directory. With the SDK 2.2.1, the framework is in /Developer/Platforms/iPhoneOS.platform/ Developer/SDKs/iPhoneOS2.0.sdk/System/Library/
PrivateFrameworks/PhotoLibrary.framework

3. Import the PLCameraController header to your application delegate. 

4. Add the following code to 'applicationDidFinishLaunching' 


- (void)applicationDidFinishLaunching:(UIApplication *)application { 

// Hide the status bar 

[[UIApplication sharedApplicationsetStatusBarHidden:YES animated:NO];

// Get the view for preview and start preview 

PLCameraController *cam = [PLCameraController sharedInstance]; 

UIView *view = [cam previewView]; 

[cam startPreview]; 


// Add the preview view to window 

[window addSubview:view]; 

// Override point for customization after app launch 

[window makeKeyAndVisible]; 


Now, run the application then you will see something like the screen show below. 


Basically, the resolution of the video coming from the camera is 304x400, which is a little weird. The preview video stream is resized in the preview view. If we do not set a new frame size, it is resized with a fixed aspect ratio and thus, there are white area at the bottom of the screen. 


For full screen preview, set the frame size of the preview view like this : 

view.frame = CGRectMake(0,0, 320, 480) ;


Update :  I tried several tests and it turns out that the preview is actually 304x400.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值