Image.GetThumbnailImage throws AccessViolationException on WIN7 BE

B

Bellingham Coder

Also posted on MSDN Forum here:
http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/e1385e33-eeb2-432b-8f90-86d846e2135a/

It seems like the System.Drawing.Image.GetThumbnailImage method always fails
with an AccessViolationException on the Windows 7 Beta.

Here's the AccessViolationException stack trace:

System.AccessViolationException: Attempted to read or write protected
memory. This is often an indication that other memory is corrupt.
at System.Drawing.SafeNativeMethods.Gdip.GdipGetImageThumbnail(HandleRef
image, Int32 thumbWidth, Int32 thumbHeight, IntPtr& thumbImage,
GetThumbnailImageAbort callback, IntPtr callbackdata)
at System.Drawing.Image.GetThumbnailImage(Int32 thumbWidth, Int32
thumbHeight, GetThumbnailImageAbort callback, IntPtr callbackData)
at TestThumbnailGeneration.Form1.generateThumbnailImage(Image srcImage,
Int32 destWidth, Int32 destHeight) in Form1.cs:line 120

I also occasionally see a SEHException with the following callstack:
0033de94()
GdiPlus.dll!CopyOnWriteBitmap::pipeLockBits() + 0x46 bytes
GdiPlus.dll!GpBitmap::pipeLockBits() + 0x50 bytes
GdiPlus.dll!GpBitmap::GetThumbnail() + 0x2cb bytes
GdiPlus.dll!_GdipGetImageThumbnail@24() + 0xd4 bytes
[Managed to Native Transition]
System.Drawing.dll!System.Drawing.Image.GetThumbnailImage(int thumbWidth,
int thumbHeight, System.Drawing.Image.GetThumbnailImageAbort callback,
System.IntPtr callbackData) + 0x3d bytes


Just an FYI for everyone out there: I've noticed that on Windows 7 the
GetThumbnailImageAbort callback delegate gets called. According to MSDN
documentation this delegate never gets called.

Since the GetThumbnailImage method seems to be behaving differently on
Windows 7 I'm trying to decide if I should just remove this call and replace
it with a DrawImage call that scales down the image with the interpolation
mode set to HighQualityBicubic.

The below method duplicates the problem. Although I try to handle the
AccessViolationException it appears that the srcImage object is not freed and
results in a InvalidOperationException ("Object is in use elsewhere.") the
next time the srcImage is accessed.

private Image generateThumbnailImage(Image srcImage, int destWidth, int
destHeight)
{
Bitmap thumbnail = new Bitmap(destWidth, destHeight);
Graphics gc = Graphics.FromImage(thumbnail);

try
{
/// Throws AccessViolationException on Windows 7 Beta
gc.DrawImage(
srcImage.GetThumbnailImage(destWidth, destHeight, new
Image.GetThumbnailImageAbort(this.ThumbnailAbort), IntPtr.Zero),
new Rectangle(0, 0, destWidth, destHeight),
new Rectangle(0, 0, destWidth, destHeight),
GraphicsUnit.Pixel);
}
catch (AccessViolationException av)
{
gc.Dispose();
return null;
}

///
/// Generating a Thumbnail via a Scaling DrawImage call.
///
//gc.InterpolationMode = InterpolationMode.HighQualityBicubic;
//gc.DrawImage(mainImage, 0, 0, destWidth, destHeight);

gc.Flush();
gc.Dispose();
return thumbnail;
}

Questions:
Anyone know how I can get the GetThumbnailImage method working on Windows 7?

Should I just scrap the call to GetThumbnailImage altogether and simply
scale it with the DrawImage method instead?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top