Skip to content

Commit

Permalink
fix crash on GdiPartialReader
Browse files Browse the repository at this point in the history
  • Loading branch information
Aytackydln committed Oct 14, 2024
1 parent 1c09105 commit 1a2adcb
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public sealed class GdiPartialCopyBitmapReader : IBitmapReader
{
//B, G, R, A
private static readonly long[] ColorData = [0L, 0L, 0L, 0L];
private static readonly Dictionary<Size, BitmapData> Bitmaps = new();
private static readonly Dictionary<Size, BitmapData> Bitmaps = new(20);
// ReSharper disable once CollectionNeverQueried.Local //to keep reference
private static readonly Dictionary<Size, int[]> BitmapBuffers = new();
private static readonly Dictionary<Size, int[]> BitmapBuffers = new(20);

private readonly Bitmap _bitmap;
private readonly Size _bitmapSize;
private readonly Size _bitmapSize = Size.Empty;
private readonly RectangleF _dimension;

public GdiPartialCopyBitmapReader(Bitmap bitmap)
Expand All @@ -41,7 +41,7 @@ public Color GetRegionColor(Rectangle rectangle)
ColorData[2] = 0L;
ColorData[3] = 0L;

if (!Bitmaps.TryGetValue(_bitmapSize, out var buff))
if (!Bitmaps.TryGetValue(rectangle.Size, out var buff))
{
var bitmapBuffer = new int[rectangle.Width * rectangle.Height];
BitmapBuffers[rectangle.Size] = bitmapBuffer;
Expand All @@ -58,7 +58,7 @@ public Color GetRegionColor(Rectangle rectangle)
Scan0 = buffer
};

Bitmaps[_bitmapSize] = buff;
Bitmaps[rectangle.Size] = buff;
}

var srcData = _bitmap.LockBits(
Expand Down

0 comments on commit 1a2adcb

Please sign in to comment.