{"record":{"id":"953ede0f45e187ac","repo":"SubtitleEdit/subtitleedit","slug":"could-not-determine-original-image-dimensions","errorCode":null,"errorMessage":"Could not determine original image dimensions.","messagePattern":"Could not determine original image dimensions\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/ui/Logic/Ocr/GoogleLens/Lens.cs","lineNumber":38,"sourceCode":"        {\n            Console.WriteLine($\"Lens constructor expects a dictionary, got {config.GetType()}\");\n            config = new Dictionary<string, object>();\n        }\n    }\n\n    public async Task<LensResult> ScanByBitmap(SKBitmap bitmap, string twoLetterLanguageCode)\n    {\n        if (bitmap == null)\n        {\n            throw new ArgumentNullException(nameof(bitmap));\n        }\n\n        var originalWidth = bitmap.Width;\n        var originalHeight = bitmap.Height;\n\n        if (originalWidth == 0 || originalHeight == 0)\n        {\n            throw new Exception(\"Could not determine original image dimensions.\");\n        }\n\n        var bitmapToProcess = bitmap;\n        var finalMime = \"image/png\";\n\n        const int MAX_DIMENSION = 1200;\n\n        // Only process if absolutely necessary\n        if (originalWidth > MAX_DIMENSION || originalHeight > MAX_DIMENSION)\n        {\n            // Calculate new dimensions maintaining aspect ratio\n            float ratio = Math.Min((float)MAX_DIMENSION / originalWidth, (float)MAX_DIMENSION / originalHeight);\n            int newWidth = (int)(originalWidth * ratio);\n            int newHeight = (int)(originalHeight * ratio);\n\n            using var resized = bitmap.Resize(new SKImageInfo(newWidth, newHeight), new SKSamplingOptions(SKFilterMode.Linear, SKMipmapMode.Linear));\n            if (resized == null)\n            {","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/ui/Logic/Ocr/GoogleLens/Lens.cs#L20-L56","documentation":"Thrown by Lens.ScanByBitmap when the supplied SKBitmap has a Width or Height of 0. A zero-dimension bitmap cannot be processed or uploaded (and cannot be resized), so the method aborts before any work. This guards against uninitialized or empty bitmaps reaching the OCR pipeline.","triggerScenarios":"Passing a default/uninitialized SKBitmap, a bitmap from a failed decode that still reports 0x0, or a programmatically created bitmap whose info had zero dimensions.","commonSituations":"A prior SKBitmap.Decode returned an empty bitmap that was not null-checked; constructing SKBitmap with a zero-size SKImageInfo; a bitmap whose underlying native object was disposed/empty.","solutions":["Null- and dimension-check the bitmap before calling ScanByBitmap (bitmap != null && bitmap.Width > 0 && bitmap.Height > 0).","Validate the source of the bitmap (decode result) and reject empties upstream.","Ensure the bitmap is created from valid SKImageInfo with non-zero dimensions.","Surface a user-facing 'invalid image' message instead of letting the exception propagate."],"exampleFix":"// before\nvar result = await lens.ScanByBitmap(bitmap, lang);\n\n// after\nif (bitmap == null || bitmap.Width == 0 || bitmap.Height == 0) throw new ArgumentException(\"Invalid bitmap\");\nvar result = await lens.ScanByBitmap(bitmap, lang);","handlingStrategy":"validation","validationCode":"if (bitmap == null) throw new ArgumentNullException(nameof(bitmap));\nif (bitmap.Width == 0 || bitmap.Height == 0) throw new ArgumentException(\"Bitmap has zero dimensions\");\nvar r = await lens.ScanByBitmap(bitmap, lang);","typeGuard":"static bool IsValidBitmap(SKBitmap b) => b != null && b.Width > 0 && b.Height > 0;","tryCatchPattern":"try { var r = await lens.ScanByBitmap(bitmap, lang); }\ncatch (Exception ex) when (ex.Message.Contains(\"original image dimensions\")) { /* notify user */ }","preventionTips":["Null- and dimension-check bitmaps before OCR.","Reject empty bitmaps from failed decodes upstream.","Create bitmaps from valid SKImageInfo only.","Surface a user-facing 'invalid image' message."],"tags":["google-lens","ocr","image","skiasharp","bitmap","validation"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}