Si verificano problemi con il mio metodo AVCaptureVideoPreviewLayer quando si acquisisce un UIImage ritagliato dello schermo visualizzabile. Attualmente funziona, ma non emette il raccolto corretto di cui ho bisogno.Ritaglio di AVCaptureVideoPreviewLayer su un quadrato
Sto provando ad emettere un quadrato ma sembra che stia dando l'altezza e comprimendo l'immagine.
L'immagine precedente mostra la schermata LIVE e l'immagine successiva mostra l'immagine dopo aver premuto il pulsante di acquisizione. Puoi vedere che è stato modificato verticalmente per adattarsi al quadrato, ma l'altezza non è stata ritagliata verticalmente.
Codice Acquisizione Immagine
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
if (imageSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
[self processImage:[UIImage imageWithData:imageData]];
}
}];
Ritaglio codice
- (void) processImage:(UIImage *)image { //process captured image, crop, resize and rotate
haveImage = YES;
CGRect deviceScreen = _previewLayer.bounds;
CGFloat width = deviceScreen.size.width;
CGFloat height = deviceScreen.size.height;
NSLog(@"WIDTH %f", width); // Outputing 320
NSLog(@"HEIGHT %f", height); // Outputting 320
UIGraphicsBeginImageContext(CGSizeMake(width, width));
[image drawInRect: CGRectMake(0, 0, width, width)];
UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGRect cropRect = CGRectMake(0, 0, width, width);
CGImageRef imageRef = CGImageCreateWithImageInRect([smallImage CGImage], cropRect);
CGImageRelease(imageRef);
[captureImageGrab setImage:[UIImage imageWithCGImage:imageRef]];
}
Potrebbe anche registrare la dimensione dell'immagine all'interno di 'processImage'? E anche cosa 'captureImageGrab'? È un 'UIImageView'? –