* Bitmap.jvm.cs: fixed InternalSave
authorVladimir Krasnov <krasnov@mono-cvs.ximian.com>
Thu, 27 Oct 2005 14:27:34 +0000 (14:27 -0000)
committerVladimir Krasnov <krasnov@mono-cvs.ximian.com>
Thu, 27 Oct 2005 14:27:34 +0000 (14:27 -0000)
* Image.jvm.cs: fixed Save

svn path=/trunk/mcs/; revision=52289

mcs/class/System.Drawing/System.Drawing/Bitmap.jvm.cs
mcs/class/System.Drawing/System.Drawing/ChangeLog
mcs/class/System.Drawing/System.Drawing/Image.jvm.cs

index f7f56174ed83903781d93de7d199065c26506efe..47b9091cbbf3a3f2f6980cecd0873c02a9994aff 100644 (file)
@@ -187,13 +187,6 @@ namespace System.Drawing
 
                                ic.NativeStream = output;
                                ic.WritePlainImage( plainImage );
-                               
-                               try {
-                                       output.close();
-                               }
-                               catch (java.io.IOException ex) {
-                                       throw new System.IO.IOException(ex.Message, ex);
-                               }
                        }
                }
 
index bfd12b2f25085657808f8ebc1d444de8d905b267..693ed75402b7a024373750d1e4ca4fd3e065e768 100644 (file)
@@ -1,3 +1,8 @@
+2005-10-27 Vladimir Krasnov <vladimirk@mainsoft.com>
+
+       * Bitmap.jvm.cs: fixed InternalSave
+       * Image.jvm.cs: fixed Save
+
 2005-10-27 Vladimir Krasnov <vladimirk@mainsoft.com>
 
        * Image.jvm.cs: fixed redolution properties
index 40fbbbda2e0a53c2a72df7a52aa7df80a8cd0b24..e1e0f02553535edd70bcf982cb89b55fd352f1a6 100644 (file)
@@ -296,17 +296,22 @@ namespace System.Drawing {
 
                public void Save (Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) {
                        //TBD: implement encoderParams
-                       java.io.OutputStream jos = vmw.common.IOUtils.ToOutputStream (stream);
-                       MemoryCacheImageOutputStream output = new MemoryCacheImageOutputStream(jos);
-               
-                       InternalSave (output, encoder.Clsid);
+                       if (encoder == null)
+                               throw new ArgumentNullException("Value cannot be null.");
+
+                       try {
+                               java.io.OutputStream jos = vmw.common.IOUtils.ToOutputStream (stream);
+                               MemoryCacheImageOutputStream output = new MemoryCacheImageOutputStream(jos);
+                               InternalSave (output, encoder.Clsid);
+                       }
+                       catch (java.io.IOException ex) {
+                               throw new System.IO.IOException(ex.Message, ex);
+                       }
                }
        
                public void Save(string filename, ImageCodecInfo encoder, EncoderParameters encoderParams) {
-                       //TBD: implement encoderParams
-                       java.io.File jf = vmw.common.IOUtils.getJavaFile (filename);
-                       FileImageOutputStream output = new FileImageOutputStream (jf);
-                       InternalSave (output, encoder.Clsid);
+                       using (Stream outputStream = new FileStream(filename, FileMode.Create))
+                               Save(outputStream, encoder, encoderParams);
                }
 
                public void Save (string filename) {
@@ -314,13 +319,16 @@ namespace System.Drawing {
                }
 
                public void Save (Stream stream, ImageFormat format) {
-                       Save (stream, ImageCodec.FindEncoder (
-                               ImageCodec.ImageFormatToClsid (format)), null);
+                       ImageCodecInfo encoder = ImageCodec.FindEncoder ( ImageCodec.ImageFormatToClsid (format) );
+                       if (encoder == null)
+                               throw new NotSupportedException("The requested format encoder is not supported");
+
+                       Save (stream, encoder, null);
                }
 
                public void Save(string filename, ImageFormat format) {
-                       Save (filename, ImageCodec.FindEncoder (
-                               ImageCodec.ImageFormatToClsid (format)), null);
+                       using (Stream outputStream = new FileStream(filename, FileMode.Create))
+                               Save(outputStream, format);
                }
                #endregion