2010-12-06 44 views
3

Je voudrais avoir une fonction dans mon application quiSuperposition un cadre sur la vue de l'appareil photo, puis enregistrer et d'utiliser la photo obtenue (ce qui a été capturé et le cadre de recouvrement)

-permet prendre une photo de vous-même ou autre qui a une renommée par exemple "Wanted:" superposé dessus.

utilisateur -Le serait alors prendre la photo et la superposition et la photo serait combinés en un seul

-L'image résultant utilisable dans le code.

Toutes les idées où/comment commencer avec cela. Tutoriels, etc.

Vive

Répondre

3

Il peut être un peu délicat, face à la transform appliquée à l'aperçu de l'image qui le rend un peu différent de celui que vous obtenez remis par la caméra, mais ici est l'idée de base:

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

quand j'utilise [(UIImage *) overlayImage drawInRect: CGRectMake (0, 0, hardwareScreenSize.width, hardwareScreenSize.height)]; il donne une image de superposition. Mais lorsque je change la position de l'image en superposition x et y, je prends un instantané et ne donne pas la nouvelle taille x et y. – Ram