iphone - 在相机 View 上叠加一个框架,然后保存并使用生成的照片(捕获的内容和叠加框架)

标签 iphone ios camera uiimagepickercontroller

我想在我的应用程序中添加一个功能

- 让您拍摄自己或其他有名望的人的照片,例如在其上叠加“通缉:”。

-然后用户拍摄照片,叠加层和照片将合并为一个

- 可在代码中使用的结果图像。

关于从哪里/如何开始的任何想法。任何教程等

干杯

最佳答案

它可能会有点棘手,处理应用于图像预览的变换,这使得它看起来与您通过相机处理的图像有点不同,但这是基本思想:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

UIImage *img = [info objectForKey:UIImagePickerControllerOriginalImage];

// Here we are throwing away lots of image resolution -- but since our art is built for the 320 x 480 screen
// and we are worried about uploading bandwidth, crunching the image down from ~1600 x 2400 to 320 x 480 just makes sense
// note that the proportion is a little different, so the picture is slightly stretched in the y-axis, but this is augmented reality, so we like that

// note that hardwareScreenSize has to be determined by checking UIDeviceHardware

UIGraphicsBeginImageContext(hardwareScreenSize);


[img drawInRect:CGRectMake(0, ((hardwareScreenSize.height - hardwareScreenSize.height ) / 2), hardwareScreenSize.width, hardwareScreenSize.height)];


// this scales overlayImage to fit ontop of camera image
[(UIImage *)overlayImage drawInRect:CGRectMake(0, 0, hardwareScreenSize.width, hardwareScreenSize.height)];

UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
[finalImage retain];

UIGraphicsEndImageContext();

关于iphone - 在相机 View 上叠加一个框架,然后保存并使用生成的照片(捕获的内容和叠加框架),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4363402/

相关文章:

ios - 我可以在 UIWebView 屏幕中使用 Hiragino Kaku Gothic ProN 字体吗?

iphone - 这些 NSMutableArray 初始化有何不同?

ios - 有没有办法在支持 iPhone 5 的应用程序中简单地使用图像?

iphone - iOS RTP 库/教程/示例

ios - 如何更新应用商店中已有的应用以包含应用内购买

javascript - 使用 Android 网络浏览器上传图书馆照片

android - CameraManager 仅提供 2 个摄像头 ID,但一个设备具有三个物理摄像头。为什么?

android - 如何旋转相机预览以在人像模式下拍摄风景照片?

iphone - 从 Info 中删除 LaunchScreen 后屏幕未满

iphone - 如何在 UIImageView 中使用 "cascade"图像模式?