0

I am trying to add an overlay image to a photo that is taken. Has anyone seen any examples on how I can do this? I want to have a picture which is a transparent PNG file, and then allow the user to take a picture with the image in it.

jscs
  • 63,694
  • 13
  • 151
  • 195
LilMoke
  • 3,176
  • 7
  • 48
  • 88
  • possible duplicate of [Saving photo with added overlay to photo library](http://stackoverflow.com/questions/5359868/saving-photo-with-added-overlay-to-photo-library) – jscs Mar 19 '12 at 20:31
  • Yes, but no solution was given. As I indicated in my post, I have not found any examples of how to do this. Thanks for trying though and I will take a look at the links,, but it does not look to promising. – LilMoke Mar 19 '12 at 20:44

1 Answers1

1

Iulius is correct that this is essentially a duplicate question. However, just to rule out one issue-- would you like the user to be able to see the overlay while composing the shot? (i.e. if your app makes different hats appear on people's heads, do you want to show the hat floating in space while they take the photo?). If you want to learn more about that, you'll need to use the cameraOverlayView property of the imagePickerController, which lets you superimpose your own view(s) on the camera. There are questions on this topic already on SO, like this one: How to add a overlay view to the cameraview and save it

Update re: scaling-- LilMoke, I assume when you say that the image is offset you're getting into trouble with the difference with the camera's aspect ratio (4:3) and the screen of the iPhone (3:4). You can define a constant and use it to set the cameraViewTransform property of your UIImagePickerController. Here's a code snippet, partially borrowed, and simplified from the excellent augmented reality tutorial at raywenderlich.com:

#define CAMERA_TRANSFORM  1.24299
// First create an overlay view for your superimposed image
overlay = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
overlay.backgroundColor=[UIColor clearColor];
overlay.opaque = NO;

UIImagePickerController *imagePicker;
imagePicker = [[[UIImagePickerController alloc] init] autorelease];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = YES; // assuming you need these?
imagePicker.toolbarHidden = YES;
imagePicker.navigationBarHidden = YES;
imagePicker.wantsFullScreenLayout = YES;
imagePicker.cameraViewTransform = CGAffineTransformScale(imagePicker.cameraViewTransform, 
    CAMERA_TRANSFORM, CAMERA_TRANSFORM); // If I understood your problem, this should help
imagePicker.cameraOverlayView = overlay;

If code along these lines doesn't get you on track, then maybe you can post all the relevant code from your troubled project here. Hopefully it's just a matter of setting the cameraViewTransform as I said above.

Community
  • 1
  • 1
Dylan
  • 126
  • 5
  • Dylan, yes that is what I want to do, but every example I find does the same thing the image is offset. When I first did this, I noticed that problem, so then I began looking for an example... and everyone shares the same problem and no one seems to address it. It appears to me to be a scaling issue, but i am not sure. – LilMoke Mar 20 '12 at 15:09
  • @LilMoke Does changing the cameraViewTransform property of the ImagePickerController help as described above? – Dylan Mar 21 '12 at 17:05
  • Dylan, I am back on this and have not got it working yet. Basically my code follows this post: http://stackoverflow.com/questions/2076456/watermark-image-on-real-time-on-camera-view-in-iphone/2078700#2078700 I added the transform, but it did not seem to help, maybe I am doing it at the wrong time. If you are still active on the post, I can post the method which does the transform and maybe you will see the issue. Thanks for the help. – LilMoke Apr 18 '12 at 16:26