ShareX/ShareX · error · ArgumentException
The source image is empty.
Error message
The source image is empty.
What it means
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.
Source
Thrown at ShareX.Tools/Tools/IconConverter/IconConverterService.cs:47
namespace ShareX.Tools;
public enum IconBitDepth
{
Palette8 = 8,
TrueColor32 = 32
}
public static class IconConverterService
{
public static readonly int[] SupportedSizes = [16, 32, 48, 64, 128, 256];
public static byte[] Convert(SKBitmap source, IEnumerable<int> sizes, IconBitDepth bitDepth)
{
ArgumentNullException.ThrowIfNull(source);
if (source.Width <= 0 || source.Height <= 0)
{
throw new ArgumentException(Localization.Strings.IconConverterService_Source_image_empty, nameof(source));
}
int[] selectedSizes = sizes.Distinct().Order().ToArray();
if (selectedSizes.Length == 0)
{
throw new ArgumentException(Localization.Strings.IconConverterService_Select_icon_size, nameof(sizes));
}
if (selectedSizes.Any(size => !SupportedSizes.Contains(size)))
{
throw new ArgumentOutOfRangeException(nameof(sizes), Localization.Strings.IconConverterService_Unsupported_icon_size);
}
List<IconEntry> entries = new(selectedSizes.Length);
foreach (int size in selectedSizes)
{
using SKBitmap bitmap = ResizeToSquare(source, size);
View on GitHub (pinned to f7d4b6bfbf)
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.
Example fix
// before
byte[] ico = IconConverterService.Convert(bitmap, sizes, depth);
// after
if (bitmap == null || bitmap.Width <= 0 || bitmap.Height <= 0)
return; // or report invalid source
byte[] ico = IconConverterService.Convert(bitmap, sizes, depth); Defensive patterns
Strategy: validation
Validate before calling
if (source is null || source.Width <= 0 || source.Height <= 0)
throw new ArgumentException("Provide a non-empty SKBitmap.", nameof(source)); Type guard
static bool IsValidIconSource(SKBitmap b) => b is { Width: > 0, Height: > 0 }; Try / catch
try { ico = IconConverterService.Convert(src, sizes, depth); }
catch (ArgumentException ex) when (ex.ParamName == nameof(src))
{ /* re-decode the source file, surface 'invalid source image' */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- At least one icon size must be selected.
- SkiaSharp returned no bitmap.
- One or more icon sizes are not supported.
- Stream is larger than the maximum allowed size.
- A valid text file path is required.
AI-assisted analysis of ShareX/ShareX@f7d4b6bfbf (2026-08-13).
Data as JSON: /api/errors/fa94c392171cf854.
Report an issue: GitHub.