+2006-07-04 Sebastien Pouliot <sebastien@ximian.com>
+
+ * Image.cs: Made GetThumbnailImage throw OutOfMemoryException when
+ image size is invalid (to match MS behaviour), also ensure that the
+ Graphics instance is disposed even if CheckStatus throws an exception.
+
2006-06-26 Sebastien Pouliot <sebastien@ximian.com>
* Pen.cs: Ensure we dispose of an existing brush before replacing it.
return item;
}
- public Image GetThumbnailImage(int thumbWidth, int thumbHeight, Image.GetThumbnailImageAbort callback, IntPtr callbackData)
+ public Image GetThumbnailImage (int thumbWidth, int thumbHeight, Image.GetThumbnailImageAbort callback, IntPtr callbackData)
{
- Status status;
- Image ThumbNail;
- Graphics g;
+ if ((thumbWidth <= 0) || (thumbHeight <= 0))
+ throw new OutOfMemoryException ("Invalid thumbnail size");
- ThumbNail=new Bitmap(thumbWidth, thumbHeight);
- g=Graphics.FromImage(ThumbNail);
-
- status = GDIPlus.GdipDrawImageRectRectI(g.nativeObject, nativeObject,
- 0, 0, thumbWidth, thumbHeight,
- 0, 0, this.Width, this.Height,
- GraphicsUnit.Pixel, IntPtr.Zero, null, IntPtr.Zero);
- GDIPlus.CheckStatus (status);
- g.Dispose();
-
- return(ThumbNail);
+ Image ThumbNail = new Bitmap (thumbWidth, thumbHeight);
+
+ using (Graphics g = Graphics.FromImage (ThumbNail)) {
+ Status status = GDIPlus.GdipDrawImageRectRectI (g.nativeObject, nativeObject,
+ 0, 0, thumbWidth, thumbHeight,
+ 0, 0, this.Width, this.Height,
+ GraphicsUnit.Pixel, IntPtr.Zero, null, IntPtr.Zero);
+
+ GDIPlus.CheckStatus (status);
+ }
+
+ return ThumbNail;
}