iPhone : take photo with front camera programmatically

后端 未结 3 497
傲寒
傲寒 2020-12-30 13:09

i want to take a picture programmatically by the front camera in my iphone app i don\'t want the user to pick or do any interaction with the image picker .. just want to

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-30 13:31

    try this--

       - (IBAction) scanButtonTapped
              {
             // ADD: present a barcode reader that scans from the camera feed
                ZBarReaderViewController *reader = [ZBarReaderViewController new];
                reader.readerDelegate = self;
                 reader.supportedOrientationsMask = ZBarOrientationMaskAll;
    
                  ZBarImageScanner *scanner = reader.scanner;
               // TODO: (optional) additional reader configuration here
    
              // EXAMPLE: disable rarely used I2/5 to improve performance
                   [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];
    
              // present and release the controller
                   [self presentModalViewController: reader
                             animated: YES];
                   [reader release];
        }
        - (void) imagePickerController: (UIImagePickerController*) reader
           didFinishPickingMediaWithInfo: (NSDictionary*) info
            { 
              // ADD: get the decode results
                 id results =
                   [info objectForKey: ZBarReaderControllerResults];
                   ZBarSymbol *symbol = nil;
                   for(symbol in results)
                       // EXAMPLE: just grab the first barcode
                          break;
    
                       // EXAMPLE: do something useful with the barcode data
                          resultText.text = symbol.data;
                          bid.text=symbol.data;
    
                       // EXAMPLE: do something useful with the barcode image
                          resultImage.image =
                          [info objectForKey: UIImagePickerControllerOriginalImage];
    
                       // ADD: dismiss the controller (NB dismiss from the *reader*!)
                          [reader dismissModalViewControllerAnimated: YES];
                     }
    

提交回复
热议问题