{"record":{"id":"94d7ec4e498d524a","repo":"HandyOrg/HandyControl","slug":"gdiplusinvalidsize","errorCode":null,"errorMessage":"GdiplusInvalidSize","messagePattern":"GdiplusInvalidSize","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Shared/HandyControl_Shared/Controls/Image/GifImage.cs","lineNumber":473,"sourceCode":"    }\n\n    [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]\n    [EditorBrowsable(EditorBrowsableState.Advanced)]\n    [ResourceExposure(ResourceScope.Machine)]\n    [ResourceConsumption(ResourceScope.Machine)]\n    internal IntPtr GetHbitmap() => GetHbitmap(Colors.LightGray);\n\n    [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]\n    [EditorBrowsable(EditorBrowsableState.Advanced)]\n    [ResourceExposure(ResourceScope.Machine)]\n    [ResourceConsumption(ResourceScope.Machine)]\n    internal IntPtr GetHbitmap(Color background)\n    {\n        var status = InteropMethods.Gdip.GdipCreateHBITMAPFromBitmap(new HandleRef(this, NativeImage), out var hBitmap,\n            ColorHelper.ToWin32(background));\n        if (status == 2 && (Width >= short.MaxValue || Height >= short.MaxValue))\n        {\n            throw new ArgumentException(\"GdiplusInvalidSize\");\n        }\n\n        if (status != InteropMethods.Gdip.Ok && NativeImage != IntPtr.Zero)\n        {\n            throw InteropMethods.Gdip.StatusException(status);\n        }\n\n        return hBitmap;\n    }\n\n    private void GetBitmapSource()\n    {\n        var handle = IntPtr.Zero;\n\n        try\n        {\n            handle = GetHbitmap();\n            Source = Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty,","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/HandyControl_Shared/Controls/Image/GifImage.cs#L455-L491","documentation":"GifImage.GetHbitmap converts the native GDI+ bitmap to an HBITMAP. When GDI+ returns status 2 (InvalidParameter/InvalidSize) and the image dimensions are >= short.MaxValue, the method throws ArgumentException('GdiplusInvalidSize') because GDI+ HBITMAPs cannot represent such large bitmaps.","triggerScenarios":"Calling GetHbitmap on a GifImage whose Width or Height is >= 32767 pixels.","commonSituations":"Rendering extremely large/tall GIFs (panoramas, long scrolling screenshots exported as GIF); converting huge bitmaps for Win32 interop / clipboard / drag-drop.","solutions":["Downscale the image to below 32767x32767 before calling GetHbitmap","Catch ArgumentException and handle oversized images with a different rendering path","Pre-check Width/Height of the GifImage and refuse interop conversion for oversized ones"],"exampleFix":"// before\nvar hBitmap = gif.GetHbitmap(Colors.Black); // throws for huge images\n// after\nif (gif.Width < short.MaxValue && gif.Height < short.MaxValue)\n{\n    var hBitmap = gif.GetHbitmap(Colors.Black);\n}","handlingStrategy":"validation","validationCode":"if (gif.Width < short.MaxValue && gif.Height < short.MaxValue) { var hb = gif.GetHbitmap(bg); }","typeGuard":"static bool CanGetHbitmap(GifImage g) => g.Width < short.MaxValue && g.Height < short.MaxValue;","tryCatchPattern":"try { return gif.GetHbitmap(background); }\ncatch (ArgumentException) { return IntPtr.Zero; }","preventionTips":["Keep GIF dimensions below 32767 px","Pre-scale oversized images","Use alternative rendering for very large images"],"tags":["gdiplus","bitmap","interop"],"backgroundTag":"argument-out-of-range","analyzedSha":"2c0875ebd67326e0c67282967e3e809c69282fee","analyzedAt":"2026-09-14T14:45:29.754Z","contentChangedAt":"2026-09-14T14:45:29.754Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}