more image methods implemented
authorJordi Mas i Hernandez <jordi@mono-cvs.ximian.com>
Wed, 31 Mar 2004 15:15:18 +0000 (15:15 -0000)
committerJordi Mas i Hernandez <jordi@mono-cvs.ximian.com>
Wed, 31 Mar 2004 15:15:18 +0000 (15:15 -0000)
svn path=/trunk/mcs/; revision=24848

mcs/class/System.Drawing/System.Drawing.Imaging/ChangeLog
mcs/class/System.Drawing/System.Drawing.Imaging/FrameDimension.cs
mcs/class/System.Drawing/System.Drawing.Imaging/ImageAttributes.cs
mcs/class/System.Drawing/System.Drawing/ChangeLog
mcs/class/System.Drawing/System.Drawing/Image.cs
mcs/class/System.Drawing/System.Drawing/gdipFunctions.cs
mcs/class/System.Drawing/Test/System.Drawing/TestBitmap.cs
mcs/class/System.Drawing/Test/System.Drawing/image1.cs

index c98af4d0b03847f52ab81875e78b7c00f903d883..40d7685ff2b5c5e385205ce921b536ea98ae9ffe 100644 (file)
@@ -1,3 +1,6 @@
+2004-03-31 Jordi Mas i Hernadez <jordi@ximian.com>
+       * FrameDimension.cs: added missing members 
+       
 2004-03-26 Jordi Mas i Hernadez <jordi@ximian.com>
        * ImageAttributes.cs: added missing members and complete the wrapper    
 
index cc6b06dda7f79454afb8954d82944a35b19eb238..043bed9a6f66d8707de3ea3f6b8f67afa3e669bb 100644 (file)
@@ -5,8 +5,8 @@
 // Author: Christian Meyer\r
 // eMail: Christian.Meyer@cs.tum.edu\r
 // Dennis Hayes (dennish@raytek.com)\r
-// Sanjay Gupta <gsanjay@novell.com)\r
-//\r
+// Sanjay Gupta <gsanjay@novell.com>\r
+// Jordi Mas i Hernanez (jordi@ximian.com)\r
 \r
 namespace System.Drawing.Imaging {\r
 \r
@@ -15,8 +15,9 @@ using System;
 public sealed class FrameDimension {\r
 \r
        internal Guid guid;\r
+       \r
        // constructor\r
-       public FrameDimension (Guid guid) \r
+       public FrameDimension(Guid guid) \r
        {\r
                this.guid = guid;\r
        }\r
@@ -30,36 +31,45 @@ public sealed class FrameDimension {
                                                                                                                                                                                                                                                                                                                                 \r
        public static FrameDimension Page {\r
                get {\r
-                       return new FrameDimension ( new Guid ( "7462dc86-6180-4c7e-8e3f-ee7333a7a483" ) );\r
+                       return new FrameDimension (new Guid ("7462dc86-6180-4c7e-8e3f-ee7333a7a483"));\r
                }\r
        }\r
        \r
        public static FrameDimension Resolution {\r
                get {\r
-                       return new FrameDimension ( new Guid ( "84236f7b-3bd3-428f-8dab-4ea1439ca315" ) );                      \r
+                       return new FrameDimension (new Guid ("84236f7b-3bd3-428f-8dab-4ea1439ca315" ));                 \r
                }\r
        }\r
        \r
        public static FrameDimension Time {\r
                get {\r
-                       return new FrameDimension ( new Guid ( "6aedbd6d-3fb5-418a-83a6-7f45229dc872" ) );                      \r
+                       return new FrameDimension (new Guid ("6aedbd6d-3fb5-418a-83a6-7f45229dc872" ));                 \r
                }\r
        }\r
        \r
-    //methods\r
-       public override bool Equals (object o) {\r
-               throw new NotImplementedException ();\r
+       //methods\r
+       public override bool Equals(object o) \r
+       {\r
+               if (!(o is FrameDimension))\r
+                       return false;           \r
+               \r
+               return (guid == ((FrameDimension)o).guid);                      \r
        }\r
        \r
-       public override int GetHashCode () {\r
-               throw new NotImplementedException ();\r
+       public override int GetHashCode() \r
+       {\r
+               return guid.GetHashCode ();\r
        }\r
        \r
-       public override string ToString() {\r
-               throw new NotImplementedException ();\r
+       public override string ToString() \r
+       {\r
+               return "FrameDimension :" + guid;\r
        }\r
 \r
        //destructor\r
-       ~FrameDimension () {}\r
+       ~FrameDimension() \r
+       {\r
+       \r
+       }\r
 }\r
 }\r
index 0b35dfb367a7c8151be9e216d540da66d70788fb..c197e35f565a34194814230f30b73cbfccfbbb6f 100644 (file)
@@ -211,16 +211,12 @@ namespace System.Drawing.Imaging
                        System.GC.SuppressFinalize (this);
                }
 
-               ~ImageAttributes() {
+               ~ImageAttributes() 
+               {
                        
                        Dispose (false);
                }
 
-               [MonoTODO]
-               object ICloneable.Clone()
-               {
-                       throw new NotImplementedException ();
-               }
                
                
                public object Clone()
index 5f72e4e5bf590f61a49e1bb9f833d30e700808e5..937802568718ed5ef7328def822888ffc0e9581b 100644 (file)
@@ -1,3 +1,5 @@
+2004-03-30  Jordi Mas i Hernandez <jordi@ximian.com>   
+       * Image.cs: implemented a few GDI+ wrapper calls
 2004-03-30  Jordi Mas i Hernandez <jordi@ximian.com>
        * Bitmap.cs: remove redundant data already present at Image.cs
        * Image.cs: use GDI+ functions to get image details
index 1f8454e0037580dea253049d73db77106a0e48d9..ba5dcd51d15cb3dc605220c2f3c4148a208ec8ba 100644 (file)
@@ -208,7 +208,14 @@ public abstract class Image : MarshalByRefObject, IDisposable , ICloneable, ISer
        
        public int GetFrameCount(FrameDimension dimension)
        {
-               throw new NotImplementedException ();
+               int count;
+               Guid guid = dimension.Guid;
+               
+               Status status = GDIPlus.GdipImageGetFrameCount (nativeObject, ref guid, out  count);
+               GDIPlus.CheckStatus (status);           
+               
+               return count;
+               
        }
        
        [MonoTODO]      
@@ -279,16 +286,20 @@ public abstract class Image : MarshalByRefObject, IDisposable , ICloneable, ISer
                Marshal.FreeHGlobal (gdipalette);                                               
        }
 
-       [MonoTODO]      
+       [MonoTODO ("Ignoring EncoderParameters")]       
        public void Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
        {
-               throw new NotImplementedException ();
+               encoder.encode(this, stream);
        }
        
-       [MonoTODO]      
+       [MonoTODO ("Ignoring EncoderParameters")]       
        public void Save(string filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
        {
-               throw new NotImplementedException ();
+               FileStream fs = new FileStream (filename, FileMode.Create);
+               encoder.encode(this, fs);
+               fs.Flush();
+               fs.Close();
+               
        }
        
        [MonoTODO]      
@@ -303,10 +314,15 @@ public abstract class Image : MarshalByRefObject, IDisposable , ICloneable, ISer
                throw new NotImplementedException ();
        }
        
-       [MonoTODO]      
+       
        public int SelectActiveFrame(FrameDimension dimension, int frameIndex)
        {
-               throw new NotImplementedException ();
+               Guid guid = dimension.Guid;             
+                               
+               Status status = GDIPlus.GdipImageSelectActiveFrame (nativeObject, ref guid, frameIndex);                        
+               GDIPlus.CheckStatus (status);                   
+               
+               return frameIndex;              
        }
        
        [MonoTODO]      
@@ -315,11 +331,14 @@ public abstract class Image : MarshalByRefObject, IDisposable , ICloneable, ISer
                throw new NotImplementedException ();
        }
 
-       // properties
-       [MonoTODO]      
+       // properties   
        public int Flags {
                get {
-                       throw new NotImplementedException ();
+                       int flags;
+                       
+                       Status status = GDIPlus.GdipGetImageFlags (nativeObject, out flags);                    
+                       GDIPlus.CheckStatus (status);                                           
+                       return flags;                   
                }
        }
        
@@ -357,8 +376,7 @@ public abstract class Image : MarshalByRefObject, IDisposable , ICloneable, ISer
                        return colorPalette;
                }
                set {
-                       colorPalette = value;           
-                       
+                       colorPalette = value;                                   
                }
        }
        
@@ -370,7 +388,7 @@ public abstract class Image : MarshalByRefObject, IDisposable , ICloneable, ISer
                        Status status = GDIPlus.GdipGetImageDimension (nativeObject, out width, out height);            
                        GDIPlus.CheckStatus (status);                   
                        
-                       return new SizeF(width,  height);
+                       return new SizeF (width, height);
                }
        }
        
@@ -468,15 +486,9 @@ public abstract class Image : MarshalByRefObject, IDisposable , ICloneable, ISer
                }
        }
        
-       [MonoTODO]
-       object ICloneable.Clone()
-       {
-               throw new NotImplementedException ();
-       }
-       
        
        public virtual object Clone()
-       {               
+       {                               
                IntPtr newimage = IntPtr.Zero;
                
                if (!(this is Bitmap)) 
@@ -486,7 +498,7 @@ public abstract class Image : MarshalByRefObject, IDisposable , ICloneable, ISer
                
                GDIPlus.CheckStatus (status);                   
                
-               if (!(this is Bitmap))
+               if (this is Bitmap)
                        return new Bitmap (newimage);
                
                throw new NotImplementedException (); 
index dda59a7afbf6693642101e657cdec551721d4463..8ba551c4e69a1976fc356049e01d3f372df6ae26 100644 (file)
@@ -657,7 +657,7 @@ namespace System.Drawing {
                internal static extern Status GdipDisposeImage ( IntPtr image );
 
                [DllImport("gdiplus.dll")]
-               internal static extern Status GdipGetImageFlags ( IntPtr image, out uint flag );
+               internal static extern Status GdipGetImageFlags(IntPtr image, out int flag);
 
                [DllImport("gdiplus.dll")]
                internal static extern Status GdipImageGetFrameDimensionsCount ( IntPtr image, out uint count );
@@ -720,7 +720,7 @@ namespace System.Drawing {
                internal static extern Status GdipImageGetFrameCount (IntPtr image, ref Guid guidDimension, out int count );
                
                [DllImport("gdiplus.dll")]
-               internal static extern Status GdipImageSelectActiveFrame ( IntPtr image, ref Guid guidDimension, uint frameIndex );
+               internal static extern Status GdipImageSelectActiveFrame (IntPtr image, ref Guid guidDimension, int frameIndex);
                
                [DllImport("gdiplus.dll")]
                internal static extern Status GdipGetPropertyItemSize ( IntPtr image, int propertyID, out uint propertySize );
index 5d0dbf32038190e4a1974c84b1c14508eddbc188..421aab02a776ae4a1a7e276825f3c4bc287b886c 100644 (file)
@@ -142,6 +142,20 @@ namespace MonoTests.System.Drawing{
                        AssertEquals (colororg50, colornew50);                          
                }       
                
+               [Test]
+               public void CloneImage()
+               {
+                       string sInFile = getInFile ("bitmaps/almogaver24bits.bmp");                     
+                       Bitmap  bmp = new Bitmap(sInFile);                      
+                       
+                       Bitmap bmpNew = (Bitmap) bmp.Clone ();                  
+                       
+                       AssertEquals (bmp.Width, bmpNew.Width);
+                       AssertEquals (bmp.Height, bmpNew.Height);               
+                       AssertEquals (bmp.PixelFormat, bmpNew.PixelFormat);                     
+                       
+               }       
+               
                /* Check bitmap features on a know 24-bits bitmap*/
                [Test]
                public void BitmapFeatures()
@@ -165,6 +179,18 @@ namespace MonoTests.System.Drawing{
                        AssertEquals (173, bmp.Size.Width);
                        AssertEquals (183, bmp.Size.Height);                                    
                }
-       
+               
+               [Test]
+               public void Frames()
+               {
+                       string sInFile = getInFile ("bitmaps/almogaver24bits.bmp");                     
+                       Bitmap  bmp = new Bitmap(sInFile);                                              
+                       int cnt = bmp.GetFrameCount(FrameDimension.Page);                       
+                       int active = bmp.SelectActiveFrame (FrameDimension.Page, 0);
+                       
+                       AssertEquals (1, cnt);                                                          
+                       AssertEquals (0, active);                                                               
+                       
+               }
        }
 }
index 1898a65e1b18f96c5848fe03882b103cfc3b51fb..de6310236daa7258386d1ecf87d29b48f50ddf3a 100644 (file)
@@ -16,8 +16,10 @@ namespace ImageTest1 {
                public static void Main(string[] argv) {
                        if( argv.Length == 1) {
                                Bitmap bmp = new Bitmap(argv[0]);
-                               bmp.Save(argv[0] + ".bmp", ImageFormat.Bmp);
+                               
                                Console.WriteLine("Output file " + argv[0] + ".bmp");
+                               bmp.Save("output.bmp", ImageFormat.Bmp);
+                               
                        }
                        else {
                                Console.WriteLine("usage: image1.exe <filename>");