在相机视图上叠加框架,然后保存并使用生成的照片(捕获的内容和覆盖框) [英] Overlaying a frame on the Camera View and then saving and using the resulting photo (what was captured and the overlay frame)

查看:260
本文介绍了在相机视图上叠加框架,然后保存并使用生成的照片(捕获的内容和覆盖框)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to have a feature in my app that

- 您拍摄自己或其他有名气的照片,例如Wanted:它。

-lets you take a picture of yourself or other that has a fame eg "Wanted:" overlaid on it.

- 然后用户将拍摄照片,并将照片叠加到一张照片中。

-The user then would take the photo and the overlay and photo would be combined into one

结果图像可用于代码。

-The resulting image usable in code.

任何想法在哪里/如何从这开始。任何教程等。

Any ideas where to/how to start with this. Any tutorials etc.

干杯

推荐答案

棘手,处理应用于图像的预览的变换,这使得它看起来与相机提交的图像略有不同,但是这里是基本思想:

It can get a little tricky, dealing with the transform applied to the preview of the image which makes it look a little different from the one you get handed by the camera, but here is the basic idea:

- (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();

这篇关于在相机视图上叠加框架,然后保存并使用生成的照片(捕获的内容和覆盖框)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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