2 // System.Drawing.Image.cs
4 // (C) 2002 Ximian, Inc. http://www.ximian.com
5 // Author: Christian Meyer (Christian.Meyer@cs.tum.edu)
6 // Alexandre Pigolkine (pigolkine@gmx.de)
7 // Jordi Mas i Hernandez (jordi@ximian.com)
9 namespace System.Drawing {
12 using System.Runtime.Remoting;
13 using System.Runtime.Serialization;
14 using System.Runtime.InteropServices;
15 using System.ComponentModel;
16 using System.Drawing.Imaging;
21 [Editor ("System.Drawing.Design.ImageEditor, " + Consts.AssemblySystem_Drawing_Design, typeof (System.Drawing.Design.UITypeEditor))]
22 [TypeConverter (typeof(ImageConverter))]
23 [ImmutableObject (true)]
24 public abstract class Image : MarshalByRefObject, IDisposable , ICloneable, ISerializable
26 public delegate bool GetThumbnailImageAbort();
28 internal IntPtr nativeObject = IntPtr.Zero;
29 protected ColorPalette colorPalette;
30 protected ImageFormat raw_format;
35 colorPalette = new ColorPalette();
39 private Image (SerializationInfo info, StreamingContext context)
45 void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
51 public static Image FromFile(string filename)
53 return new Bitmap (filename);
56 public static Image FromFile(string filename, bool useEmbeddedColorManagement)
58 return new Bitmap (filename, useEmbeddedColorManagement);
62 public static Bitmap FromHbitmap(IntPtr hbitmap)
64 throw new NotImplementedException ();
68 public static Bitmap FromHbitmap(IntPtr hbitmap, IntPtr hpalette)
70 throw new NotImplementedException ();
73 public static Image FromStream (Stream stream)
75 return new Bitmap (stream);
78 public static Image FromStream (Stream stream, bool useECM)
80 return new Bitmap (stream, useECM);
83 public static int GetPixelFormatSize(PixelFormat pixfmt)
87 case PixelFormat.Format16bppArgb1555:
88 case PixelFormat.Format16bppGrayScale:
89 case PixelFormat.Format16bppRgb555:
90 case PixelFormat.Format16bppRgb565:
93 case PixelFormat.Format1bppIndexed:
96 case PixelFormat.Format24bppRgb:
99 case PixelFormat.Format32bppArgb:
100 case PixelFormat.Format32bppPArgb:
101 case PixelFormat.Format32bppRgb:
104 case PixelFormat.Format48bppRgb:
107 case PixelFormat.Format4bppIndexed:
110 case PixelFormat.Format64bppArgb:
111 case PixelFormat.Format64bppPArgb:
114 case PixelFormat.Format8bppIndexed:
121 public static bool IsAlphaPixelFormat(PixelFormat pixfmt)
125 case PixelFormat.Format16bppArgb1555:
126 case PixelFormat.Format32bppArgb:
127 case PixelFormat.Format32bppPArgb:
128 case PixelFormat.Format64bppArgb:
129 case PixelFormat.Format64bppPArgb:
132 case PixelFormat.Format16bppGrayScale:
133 case PixelFormat.Format16bppRgb555:
134 case PixelFormat.Format16bppRgb565:
135 case PixelFormat.Format1bppIndexed:
136 case PixelFormat.Format24bppRgb:
137 case PixelFormat.Format32bppRgb:
138 case PixelFormat.Format48bppRgb:
139 case PixelFormat.Format4bppIndexed:
140 case PixelFormat.Format8bppIndexed:
147 public static bool IsCanonicalPixelFormat (PixelFormat pixfmt)
149 return ((pixfmt & PixelFormat.Canonical) != 0);
152 public static bool IsExtendedPixelFormat (PixelFormat pixfmt)
154 return ((pixfmt & PixelFormat.Extended) != 0);
158 public RectangleF GetBounds (ref GraphicsUnit pageUnit)
162 Status status = GDIPlus.GdipGetImageBounds (nativeObject, out source, ref pageUnit);
163 GDIPlus.CheckStatus (status);
169 public EncoderParameters GetEncoderParameterList(Guid encoder)
171 throw new NotImplementedException ();
174 public int GetFrameCount(FrameDimension dimension)
177 Guid guid = dimension.Guid;
179 Status status = GDIPlus.GdipImageGetFrameCount (nativeObject, ref guid, out count);
180 GDIPlus.CheckStatus (status);
187 public PropertyItem GetPropertyItem(int propid)
189 throw new NotImplementedException ();
193 public Image GetThumbnailImage(int thumbWidth, int thumbHeight, Image.GetThumbnailImageAbort callback, IntPtr callbackData)
195 throw new NotImplementedException ();
199 public void RemovePropertyItem (int propid)
201 throw new NotImplementedException ();
205 public void RotateFlip (RotateFlipType rotateFlipType)
207 throw new NotImplementedException ();
210 public void Save (string filename)
212 Save (filename, RawFormat);
215 public void Save (Stream stream, ImageFormat format)
217 if (Environment.OSVersion.Platform == (PlatformID) 128) {
218 byte[] g = format.Guid.ToByteArray();
219 GDIPlus.GdiPlusStreamHelper sh = new GDIPlus.GdiPlusStreamHelper (stream);
220 Status st = GDIPlus.GdipSaveImageToDelegate_linux (nativeObject, sh.PutBytesDelegate, g, IntPtr.Zero);
222 throw new NotImplementedException ("Image.Save(Stream) (win32)");
226 public void Save(string filename, ImageFormat format)
228 byte[] g = format.Guid.ToByteArray();
229 Status st = GDIPlus.GdipSaveImageToFile (nativeObject, filename, g, IntPtr.Zero);
230 GDIPlus.CheckStatus (st);
233 internal void setGDIPalette()
237 gdipalette = colorPalette.getGDIPalette ();
238 Status st = GDIPlus.GdipSetImagePalette (NativeObject, gdipalette);
239 Marshal.FreeHGlobal (gdipalette);
241 GDIPlus.CheckStatus (st);
244 [MonoTODO ("Ignoring EncoderParameters")]
245 public void Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
247 Save (stream, new ImageFormat (encoder.FormatID));
250 [MonoTODO ("Ignoring EncoderParameters")]
251 public void Save(string filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
253 Save (filename, new ImageFormat (encoder.FormatID));
257 public void SaveAdd(EncoderParameters encoderParams)
259 throw new NotImplementedException ();
263 public void SaveAdd(Image image, EncoderParameters encoderParams)
265 throw new NotImplementedException ();
269 public int SelectActiveFrame(FrameDimension dimension, int frameIndex)
271 Guid guid = dimension.Guid;
273 Status status = GDIPlus.GdipImageSelectActiveFrame (nativeObject, ref guid, frameIndex);
274 GDIPlus.CheckStatus (status);
280 public void SetPropertyItem(PropertyItem propitem)
282 throw new NotImplementedException ();
290 Status status = GDIPlus.GdipGetImageFlags (nativeObject, out flags);
291 GDIPlus.CheckStatus (status);
297 public Guid[] FrameDimensionsList {
299 throw new NotImplementedException ();
306 Status status = GDIPlus.GdipGetImageHeight (nativeObject, out height);
307 GDIPlus.CheckStatus (status);
313 public float HorizontalResolution {
317 Status status = GDIPlus.GdipGetImageHorizontalResolution (nativeObject, out resolution);
318 GDIPlus.CheckStatus (status);
324 public ColorPalette Palette {
330 colorPalette = value;
335 public SizeF PhysicalDimension {
339 Status status = GDIPlus.GdipGetImageDimension (nativeObject, out width, out height);
340 GDIPlus.CheckStatus (status);
342 return new SizeF (width, height);
346 public PixelFormat PixelFormat {
350 Status status = GDIPlus.GdipGetImagePixelFormat (nativeObject, out value);
351 GDIPlus.CheckStatus (status);
359 public int[] PropertyIdList {
361 throw new NotImplementedException ();
366 public PropertyItem[] PropertyItems {
368 throw new NotImplementedException ();
372 public ImageFormat RawFormat {
378 internal void SetRawFormat (ImageFormat format)
385 return new Size(Width, Height);
389 public float VerticalResolution {
393 GDIPlus.GdipGetImageVerticalResolution (nativeObject, out resolution);
401 Status status = GDIPlus.GdipGetImageWidth (nativeObject, out width);
402 GDIPlus.CheckStatus (status);
408 internal IntPtr NativeObject{
413 nativeObject = value;
417 public void Dispose ()
427 protected virtual void DisposeResources ()
429 GDIPlus.GdipDisposeImage (nativeObject);
432 protected virtual void Dispose (bool disposing)
434 if (nativeObject != (IntPtr) 0){
436 nativeObject=IntPtr.Zero;
441 public virtual object Clone()
443 IntPtr newimage = IntPtr.Zero;
445 if (!(this is Bitmap))
446 throw new NotImplementedException ();
448 Status status = GDIPlus.GdipCloneImage (NativeObject, out newimage);
450 GDIPlus.CheckStatus (status);
453 return new Bitmap (newimage);
455 throw new NotImplementedException ();