From aee93405f5955311cdff5f7697e682c2aee0bfc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 10 Oct 2026 15:08:43 +0200 Subject: [PATCH] iOS: Scale camera frames to the requested size instead of cropping The frame was drawn at its own size into a context of the size the game asked for, so the game got one corner of the picture. Also drop the preview layer, which was never shown. Co-Authored-By: Claude Opus 5.5 --- ios/CameraHelper.mm | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/ios/CameraHelper.mm b/ios/CameraHelper.mm index 8afce22999..5cc768789f 100644 --- a/ios/CameraHelper.mm +++ b/ios/CameraHelper.mm @@ -6,7 +6,6 @@ @interface CameraHelper() { AVCaptureSession *captureSession; - AVCaptureVideoPreviewLayer *previewLayer; int mWidth; int mHeight; } @@ -117,11 +116,6 @@ NSString *getSelectedCamera() { dispatch_queue_t queue = dispatch_queue_create("cameraQueue", NULL); [videoOutput setSampleBufferDelegate:self queue:queue]; - previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:captureSession]; - previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; - - [previewLayer setFrame:CGRectMake(0, 0, mWidth, mHeight)]; - [captureSession startRunning]; }); } @@ -156,7 +150,8 @@ NSString *getSelectedCamera() { CGImageRef inImage = CGBitmapContextCreateImage(inContext); CGContextRelease(inContext); - CGRect outRect = CGRectMake(0, 0, width, height); + // Scale the frame to the size the game asked for. + CGRect outRect = CGRectMake(0, 0, mWidth, mHeight); CGContextRef outContext = CGBitmapContextCreate(nil, mWidth, mHeight, 8, mWidth * 4, colorSpace, kCGImageAlphaPremultipliedFirst); CGContextDrawImage(outContext, outRect, inImage); CGImageRelease(inImage);