Quantcast
Channel: WriteableBitmapEx
Viewing all articles
Browse latest Browse all 360

Created Unassigned: IndexOutOfRangeException in System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawLine(System.Windows.Media.Imaging.BitmapContext context, int pixelWidth, int pixelHeight, int x1, int y1, int x2, int y2, int color) [21266]

$
0
0
When the bitmap is large, you get this exception:
Here are the sample parameter values:

pixelWidth 4391
pixelHeight 5159
x1 1197
y1 3400
x2 1197
y2 3516

I believe the issue is due to this snippet:

int index = x1s + ((y1 * pixelWidth) << PRECISION_SHIFT);

// Walk the line!
var inc = (pixelWidth << PRECISION_SHIFT) + incx;
for (int y = y1; y <= y2; ++y)
{
pixels[index >> PRECISION_SHIFT] = color;
index += inc;
}

y1 * pixelWidth grows pretty fast, so after PRESIZION_SHIFT it overflows easily (in this case it was just making the number negative.

It probably should be modified to read:

int index = x1s;
int baseValue = (y1 * pixelWidth);

// Walk the line!
var inc = (pixelWidth << PRECISION_SHIFT) + incx;
for (int y = y1; y <= y2; ++y)
{
pixels[baseValue + (index >> PRECISION_SHIFT)] = color;
index += inc;
}

Viewing all articles
Browse latest Browse all 360

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>