[winforms] Style
[mono.git] / mcs / class / System.Drawing / System.Drawing / Bitmap.cs
index 9dd608e01ff756c785add5fc8776e6f5576679ff..d88c3e129f51b24ae3f22a485c32b3e5d8cdaf91 100644 (file)
@@ -64,12 +64,26 @@ namespace System.Drawing
                        nativeObject = ptr;
                }
 
+               // Usually called when cloning images that need to have
+               // not only the handle saved, but also the underlying stream
+               // (when using MS GDI+ and IStream we must ensure the stream stays alive for all the life of the Image)
+               internal Bitmap(IntPtr ptr, Stream stream)
+               {
+                       // under Win32 stream is owned by SD/GDI+ code
+                       if (GDIPlus.RunningOnWindows ())
+                               this.stream = stream;
+                       nativeObject = ptr;
+               }
+
                public Bitmap (int width, int height) : this (width, height, PixelFormat.Format32bppArgb)
                {
                }
 
                public Bitmap (int width, int height, Graphics g)
-               {               
+               {
+                       if (g == null)
+                               throw new ArgumentNullException ("g");
+
                        IntPtr bmp;
                        Status s = GDIPlus.GdipCreateBitmapFromGraphics (width, height, g.nativeObject, out bmp);
                        GDIPlus.CheckStatus (s);
@@ -101,6 +115,9 @@ namespace System.Drawing
 
                public Bitmap (string filename, bool useIcm)
                {
+                       if (filename == null)
+                               throw new ArgumentNullException ("filename");
+
                        IntPtr imagePtr;
                        Status st;
 
@@ -115,6 +132,9 @@ namespace System.Drawing
 
                public Bitmap (Type type, string resource)
                {
+                       if (resource == null)
+                               throw new ArgumentException ("resource");
+
                        Stream s = type.Assembly.GetManifestResourceStream (type, resource);
                        if (s == null) {
                                string msg = Locale.GetText ("Resource '{0}' was not found.", resource);