{"record":{"id":"fa94c392171cf854","repo":"ShareX/ShareX","slug":"the-source-image-is-empty","errorCode":null,"errorMessage":"The source image is empty.","messagePattern":"The source image is empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"ShareX.Tools/Tools/IconConverter/IconConverterService.cs","lineNumber":47,"sourceCode":"namespace ShareX.Tools;\r\n\r\npublic enum IconBitDepth\r\n{\r\n    Palette8 = 8,\r\n    TrueColor32 = 32\r\n}\r\n\r\npublic static class IconConverterService\r\n{\r\n    public static readonly int[] SupportedSizes = [16, 32, 48, 64, 128, 256];\r\n\r\n    public static byte[] Convert(SKBitmap source, IEnumerable<int> sizes, IconBitDepth bitDepth)\r\n    {\r\n        ArgumentNullException.ThrowIfNull(source);\r\n\r\n        if (source.Width <= 0 || source.Height <= 0)\r\n        {\r\n            throw new ArgumentException(Localization.Strings.IconConverterService_Source_image_empty, nameof(source));\r\n        }\r\n\r\n        int[] selectedSizes = sizes.Distinct().Order().ToArray();\r\n        if (selectedSizes.Length == 0)\r\n        {\r\n            throw new ArgumentException(Localization.Strings.IconConverterService_Select_icon_size, nameof(sizes));\r\n        }\r\n\r\n        if (selectedSizes.Any(size => !SupportedSizes.Contains(size)))\r\n        {\r\n            throw new ArgumentOutOfRangeException(nameof(sizes), Localization.Strings.IconConverterService_Unsupported_icon_size);\r\n        }\r\n\r\n        List<IconEntry> entries = new(selectedSizes.Length);\r\n\r\n        foreach (int size in selectedSizes)\r\n        {\r\n            using SKBitmap bitmap = ResizeToSquare(source, size);\r","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/ShareX/ShareX/blob/f7d4b6bfbf58c0553c01fb038347deec54c0cc7a/ShareX.Tools/Tools/IconConverter/IconConverterService.cs#L29-L65","documentation":"Thrown by IconConverterService.Convert when the supplied SKBitmap has a Width or Height of zero or negative. The converter needs real pixel data to downscale into each icon size, so an empty/degenerate source bitmap is rejected up front rather than producing broken icons.","triggerScenarios":"Calling Convert with an SKBitmap constructed from a zero-byte or corrupt image stream, a bitmap whose Decode succeeded but dimensions are 0x0, or a disposed/uninitialized SKBitmap whose Width/Height read as non-positive.","commonSituations":"Loading an icon source from a file that failed to decode (SKBitmap.Decode returns an empty bitmap on failure rather than null); passing a programmatically created placeholder bitmap that was never drawn into; trailing edge of a corrupt PNG.","solutions":["Check the SKBitmap returned by SKBitmap.Decode for IsNull/Width>0 before passing it to Convert.","Validate the source image file is a readable raster format and not truncated.","If generating the bitmap in code, ensure it is created with explicit positive dimensions and populated."],"exampleFix":"// before\nbyte[] ico = IconConverterService.Convert(bitmap, sizes, depth);\n\n// after\nif (bitmap == null || bitmap.Width <= 0 || bitmap.Height <= 0)\n    return; // or report invalid source\nbyte[] ico = IconConverterService.Convert(bitmap, sizes, depth);","handlingStrategy":"validation","validationCode":"if (source is null || source.Width <= 0 || source.Height <= 0)\n    throw new ArgumentException(\"Provide a non-empty SKBitmap.\", nameof(source));","typeGuard":"static bool IsValidIconSource(SKBitmap b) => b is { Width: > 0, Height: > 0 };","tryCatchPattern":"try { ico = IconConverterService.Convert(src, sizes, depth); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(src))\n{ /* re-decode the source file, surface 'invalid source image' */ }","preventionTips":["After SKBitmap.Decode, check the result is non-null and has positive dimensions before use.","Wrap decode in a helper that returns a validated bitmap or null.","Reject empty bitmaps at the UI import boundary."],"tags":["icon-converter","skiasharp","validation","argument"],"backgroundTag":null,"analyzedSha":"f7d4b6bfbf58c0553c01fb038347deec54c0cc7a","analyzedAt":"2026-08-13T10:23:46.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}