iphone - iOS Camera Overlay Capture Image -
i facing real though issues. have studied couple of tutorial adding overlay in camera using uiimagepickercontroller , avfoundation. working fine me. can add overlay on camera using both. main concern extract part of image under overlay view when user hits scan button. having white view in overlay , button, image under white view should retrieved.
-(ibaction)cameraclicked:(id)sender { overlayview *overlay = [[overlayview alloc] initwithframe:cgrectmake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; self.imagepickercontroller = [[uiimagepickercontroller alloc] init]; self.imagepickercontroller.delegate = self; if ([uiimagepickercontroller iscameradeviceavailable:uiimagepickercontrollercameradevicerear]) { self.imagepickercontroller.sourcetype = uiimagepickercontrollersourcetypecamera; self.imagepickercontroller.cameracapturemode = uiimagepickercontrollercameracapturemodephoto; } else { self.imagepickercontroller.sourcetype = uiimagepickercontrollersourcetypesavedphotosalbum; } self.imagepickercontroller.showscameracontrols = no; self.imagepickercontroller.navigationbarhidden = yes; self.imagepickercontroller.toolbarhidden = yes; self.imagepickercontroller.wantsfullscreenlayout = yes; self.imagepickercontroller.cameraviewtransform = cgaffinetransformscale(self.imagepickercontroller.cameraviewtransform, camera_transform_x,camera_transform_y); self.imagepickercontroller.cameraoverlayview = overlay; [self presentviewcontroller:self.imagepickercontroller animated:yes completion:nil]; } - (void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info { uiimage *image = [info objectforkey:uiimagepickercontrolleroriginalimage]; cgrect croprect; uiimage *image = [info objectforkey:uiimagepickercontrolleroriginalimage]; uiimage *crosshair = [uiimage imagenamed:@"overlay.png"]; uigraphicsbeginimagecontext(cgsizemake(self.view.frame.size.width, self.view.frame.size.height)); [image drawinrect: cgrectmake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; uiimage *smallimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); if(isios7) croprect = cgrectmake(10, 440, crosshair.size.width, crosshair.size.height); else croprect = cgrectmake(10, 405, crosshair.size.width, crosshair.size.height); cgimageref imageref = cgimagecreatewithimageinrect([smallimage cgimage], croprect); uiimage *setimage = [uiimage imagewithcgimage:imageref]; self.finalimageview.image = setimage; [self dismissviewcontrolleranimated:yes completion:nil]; }
try this... working..
self.imagepickercontroller=nil; self.imagepickercontroller = [[uiimagepickercontroller alloc] init]; self.imagepickercontroller.sourcetype = uiimagepickercontrollersourcetypecamera; self.imagepickercontroller.delegate = self; self.imagepickercontroller.allowsediting = no; self.imagepickercontroller.showscameracontrols = no;
// create view overlay
cgrect overlayrect = cgrectmake(0, 0, self.imagepickercontroller.view.frame.size.width, self.imagepickercontroller.view.frame.size.height); uiview *overlayview = [[uiview alloc] initwithframe:overlayrect]; btn_overlay = [uibutton buttonwithtype:uibuttontypecustom]; [btn_overlay setbackgroundimage:[uiimage imagenamed:@"imagenmae"] forstate:uicontrolstatenormal]; btn_overlay.frame = cgrectmake(80.0, 170, 150.0, 30.0); btn_overlay.tag = 0; [btn_overlay settitle:@"button title" forstate:uicontrolstatenormal]; [btn_overlay addtarget:self action:@selector(actinmethod:) forcontrolevents:uicontroleventtouchupinside]; [overlayview addsubview:btn_overlay]; [self.imagepickercontroller setcameraoverlayview:overlayview]; // display imagepicker [self.navigationcontroller presentviewcontroller:self.imagepickercontroller animated:yes completion:nil];
Comments
Post a Comment