* Bitmap.jvm.cs: fixed InternalSave, to remove alpha channel of saved jpeg, fixed...
authorVladimir Krasnov <krasnov@mono-cvs.ximian.com>
Thu, 27 Oct 2005 10:27:54 +0000 (10:27 -0000)
committerVladimir Krasnov <krasnov@mono-cvs.ximian.com>
Thu, 27 Oct 2005 10:27:54 +0000 (10:27 -0000)
svn path=/trunk/mcs/; revision=52266

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

index 313b9a228372797fa9868e6315c417bc2266c614..f7f56174ed83903781d93de7d199065c26506efe 100644 (file)
@@ -17,6 +17,12 @@ namespace System.Drawing
 {
        public sealed class Bitmap : Image {
 
+               # region Static fields
+
+               static readonly image.ColorModel _jpegColorModel = new image.DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
+
+               #endregion
+
                #region constructors
 
                Bitmap (PlainImage orig) {
@@ -133,6 +139,9 @@ namespace System.Drawing
                        catch (Exception) {
                                throw new OutOfMemoryException ("Out of memory");
                        }
+                       finally {
+                               ic.Dispose();
+                       }
                }
 
                #endregion
@@ -146,9 +155,38 @@ namespace System.Drawing
                        if (ic == null)
                                ic = ImageCodec.CreateWriter( ImageFormat.Png );
 
-                       if (ic != null) {
+                       if (ic == null)
+                               throw new NotSupportedException("The requested format encoder is not supported");
+
+                       using (ic) {
+
+                               PlainImage plainImage = CurrentImage;
+                               plainImage.NativeImage.flush();
+
+                               if ( ImageCodec.ClsidToImageFormat( clsid ).Equals( ImageFormat.Jpeg ) ) {
+                                       image.ColorModel cm = ((image.BufferedImage)CurrentImage.NativeImage).getColorModel();
+                                       if (cm.hasAlpha()) {
+                                               if (cm is image.DirectColorModel) {
+                                                       image.Raster raster = ((image.BufferedImage)CurrentImage.NativeImage).getRaster();
+                                                       image.DataBuffer db = raster.getDataBuffer();
+                                                       image.DirectColorModel dcm = (image.DirectColorModel)cm;
+                                                       image.SinglePixelPackedSampleModel jpegSampleModel = new image.SinglePixelPackedSampleModel( 
+                                                               db.getDataType(), Width, Height, 
+                                                               new int[] {dcm.getRedMask(), dcm.getGreenMask(), dcm.getBlueMask()}     );
+               
+                                                       image.BufferedImage tb = new image.BufferedImage( 
+                                                               _jpegColorModel, 
+                                                               image.Raster.createWritableRaster( jpegSampleModel, db, null ),
+                                                               false, null );
+
+                                                       plainImage = new PlainImage( tb, plainImage.Thumbnails, ImageFormat.Jpeg, plainImage.HorizontalResolution, plainImage.VerticalResolution, plainImage.Dimension );
+                                                       plainImage.NativeMetadata = plainImage.NativeMetadata;
+                                               }
+                                       }
+                               }
+
                                ic.NativeStream = output;
-                               ic.WritePlainImage( CurrentImage );
+                               ic.WritePlainImage( plainImage );
                                
                                try {
                                        output.close();
@@ -157,9 +195,6 @@ namespace System.Drawing
                                        throw new System.IO.IOException(ex.Message, ex);
                                }
                        }
-                       else {
-                               throw new NotSupportedException("The requested format encoder is not supported");
-                       }
                }
 
                #endregion
@@ -231,7 +266,13 @@ namespace System.Drawing
                {
                        PlainImage plainImage = CurrentImage.Clone(false);\r
                        BufferedImage clone = new BufferedImage( (int)rect.Width, (int)rect.Height, ToBufferedImageFormat( pixFormat ) );\r
-                       clone.getGraphics().drawImage( NativeObject, -(int)rect.X, -(int)rect.Y, null );\r
+                       awt.Graphics2D g = clone.createGraphics();\r
+                       try {\r
+                               g.drawImage( NativeObject, -(int)rect.X, -(int)rect.Y, null );\r
+                       }\r
+                       finally {\r
+                               g.dispose();\r
+                       }\r
 \r
                        plainImage.NativeImage = clone;\r
                        return new Bitmap(plainImage);\r
index 5e1ac879864bb644fbfadf6aad6df3ead1ec4a6f..24d96fd9add9340fe38f9e1cb7aeacbea2568022 100644 (file)
@@ -1,3 +1,8 @@
+2005-10-27 Vladimir Krasnov <vladimirk@mainsoft.com>
+
+       * Bitmap.jvm.cs: fixed InternalSave, to remove alpha channel of saved jpeg
+       fixed clone, Initialize
+
 2005-10-24  Peter Dennis Bartok  <pbartok@novell.com>
 
        * Brush.cs: Don't delete the brush if the display handle is no longer