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

发布于 2024-10-06 08:36:43 字数 157 浏览 5 评论 0原文

我希望我的应用程序中有一个功能,

可以让您为自己或其他有名气的人拍一张照片,例如“通缉:”。

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

- 生成的图像可在代码中使用。

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

干杯

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明月松间行 2024-10-13 08:36:43

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

- (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 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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文