void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
MemoryStream ms = new MemoryStream ();
- this.Save (ms, ImageFormat.Bmp);
+ this.Save (ms, RawFormat);
info.AddValue ("Data", ms.ToArray ());
}
return new Bitmap (stream, useECM);
}
-#if NET_2_0
-
// See http://support.microsoft.com/default.aspx?scid=kb;en-us;831419 for performance discussion
- public static Image FromStream (Stream stream, bool useECM, bool validateImageData)\r
+ public static Image FromStream (Stream stream, bool useECM, bool validateImageData)
{
return new Bitmap (stream, useECM);
}
-#endif
public static int GetPixelFormatSize(PixelFormat pixfmt)
{
int result = 0;
try {
status = GDIPlus.GdipGetPropertyItem (nativeObject, propid, propSize, property);
GDIPlus.CheckStatus (status);
- gdipProperty = (GdipPropertyItem) Marshal.PtrToStructure ((IntPtr)property,
+ gdipProperty = (GdipPropertyItem) Marshal.PtrToStructure (property,
typeof (GdipPropertyItem));
GdipPropertyItem.MarshalTo (gdipProperty, item);
}
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();
+ Image ThumbNail = new Bitmap (thumbWidth, thumbHeight);
- return(ThumbNail);
+ 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;
}
}
#if NET_2_0
-
- [LocalizableAttribute(false)] \r
+ [DefaultValue (null)]
+ [LocalizableAttribute(false)]
[BindableAttribute(true)]
- [TypeConverter (typeof (StringConverter))]\r
+ [TypeConverter (typeof (StringConverter))]
public object Tag {
get { return tag; }
set { tag = value; }
Dispose (false);
}
- private void DisposeResources ()
- {
- Status status = GDIPlus.GdipDisposeImage (nativeObject);
- GDIPlus.CheckStatus (status);
- }
-
protected virtual void Dispose (bool disposing)
{
if (nativeObject != IntPtr.Zero){
- DisposeResources ();
+ Status status = GDIPlus.GdipDisposeImage (nativeObject);
+ // set nativeObject to null before throwing an exception
nativeObject = IntPtr.Zero;
+ GDIPlus.CheckStatus (status);
}
}
- public virtual object Clone()
- {
+ public object Clone ()
+ {
+ Bitmap b = (this as Bitmap);
+ if (b == null)
+ throw new NotImplementedException ("This Image instance isn't a Bitmap instance.");
IntPtr newimage = IntPtr.Zero;
-
- if (!(this is Bitmap))
- throw new NotImplementedException ();
-
Status status = GDIPlus.GdipCloneImage (NativeObject, out newimage);
GDIPlus.CheckStatus (status);
- if (this is Bitmap){
- return new Bitmap (newimage);
- }
-
- throw new NotImplementedException ();
+ return new Bitmap (newimage);
}
-
}
}