SubtitleEdit/subtitleedit · error · Exception
Could not determine original image dimensions.
Error message
Could not determine original image dimensions.
What it means
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.
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.
Example fix
// before
var result = await lens.ScanByBitmap(bitmap, lang);
// after
if (bitmap == null || bitmap.Width == 0 || bitmap.Height == 0) throw new ArgumentException("Invalid bitmap");
var result = await lens.ScanByBitmap(bitmap, lang); Defensive patterns
Strategy: validation
Validate before calling
if (bitmap == null) throw new ArgumentNullException(nameof(bitmap));
if (bitmap.Width == 0 || bitmap.Height == 0) throw new ArgumentException("Bitmap has zero dimensions");
var r = await lens.ScanByBitmap(bitmap, lang); Type guard
static bool IsValidBitmap(SKBitmap b) => b != null && b.Width > 0 && b.Height > 0;
Try / catch
try { var r = await lens.ScanByBitmap(bitmap, lang); }
catch (Exception ex) when (ex.Message.Contains("original image dimensions")) { /* notify user */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not determine image dimensions
- File type not supported
- Could not decode image
- Could not resize image
- Image dimensions are larger than 1000x1000
AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13).
Data as JSON: /api/errors/953ede0f45e187ac.
Report an issue: GitHub.
Appendix: source
Thrown at src/ui/Logic/Ocr/GoogleLens/Lens.cs:38
{
Console.WriteLine($"Lens constructor expects a dictionary, got {config.GetType()}");
config = new Dictionary<string, object>();
}
}
public async Task<LensResult> ScanByBitmap(SKBitmap bitmap, string twoLetterLanguageCode)
{
if (bitmap == null)
{
throw new ArgumentNullException(nameof(bitmap));
}
var originalWidth = bitmap.Width;
var originalHeight = bitmap.Height;
if (originalWidth == 0 || originalHeight == 0)
{
throw new Exception("Could not determine original image dimensions.");
}
var bitmapToProcess = bitmap;
var finalMime = "image/png";
const int MAX_DIMENSION = 1200;
// Only process if absolutely necessary
if (originalWidth > MAX_DIMENSION || originalHeight > MAX_DIMENSION)
{
// Calculate new dimensions maintaining aspect ratio
float ratio = Math.Min((float)MAX_DIMENSION / originalWidth, (float)MAX_DIMENSION / originalHeight);
int newWidth = (int)(originalWidth * ratio);
int newHeight = (int)(originalHeight * ratio);
using var resized = bitmap.Resize(new SKImageInfo(newWidth, newHeight), new SKSamplingOptions(SKFilterMode.Linear, SKMipmapMode.Linear));
if (resized == null)
{View on GitHub (pinned to 17a9f07487)