在相机视图上覆盖一个框架,然后保存并使用生成的照片(捕获的内容和覆盖框架)

时间:2010-12-06 05:08:36

标签: iphone ios camera uiimagepickercontroller

我想在我的应用中有一个功能

- 你拍摄自己或其他有名气的照片,例如“通缉:”覆盖在上面。

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

- 结果图像可用于代码。

任何想法,如何开始/如何开始。任何教程等。

干杯

1 个答案:

答案 0 :(得分:3)

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

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