Overlaying a frame on the Camera View and then saving and using the resulting photo (what was captured and the overlay frame)

一曲冷凌霜 提交于 2019-12-14 00:24:15

问题


I would like to have a feature in my app that

-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.

Cheers


回答1:


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


来源:https://stackoverflow.com/questions/4363402/overlaying-a-frame-on-the-camera-view-and-then-saving-and-using-the-resulting-ph

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