{
#region constructors
// constructors
+
+#if NET_2_0
+ // required for XmlSerializer (#323246)
+ private Bitmap ()
+ {
+ }
+#endif
+
internal Bitmap (IntPtr ptr)
{
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);
public Bitmap (string filename, bool useIcm)
{
+ if (filename == null)
+ throw new ArgumentNullException ("filename");
+
IntPtr imagePtr;
Status st;
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);
}
public void SetPixel (int x, int y, Color color)
- {
- Status s = GDIPlus.GdipBitmapSetPixel(nativeObject, x, y, color.ToArgb());
+ {
+ Status s = GDIPlus.GdipBitmapSetPixel (nativeObject, x, y, color.ToArgb ());
+ if (s == Status.InvalidParameter) {
+ // check is done in case of an error only to avoid another
+ // unmanaged call for normal (successful) calls
+ if ((this.PixelFormat & PixelFormat.Indexed) != 0) {
+ string msg = Locale.GetText ("SetPixel cannot be called on indexed bitmaps.");
+#if NET_2_0
+ throw new InvalidOperationException (msg);
+#else
+ throw new Exception (msg);
+#endif
+ }
+ }
GDIPlus.CheckStatus (s);
}
GDIPlus.CheckStatus (status);
}
- public void UnlockBits (BitmapData bitmap_data)
+ public void UnlockBits (BitmapData bitmapdata)
{
- Status status = GDIPlus.GdipBitmapUnlockBits (nativeObject, bitmap_data);
+ Status status = GDIPlus.GdipBitmapUnlockBits (nativeObject, bitmapdata);
GDIPlus.CheckStatus (status);
}
}