[Mono-bugs] [Bug 76844][Nor] Changed - Unlockbits fails

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Tue Nov 29 17:05:52 EST 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by miguel at ximian.com.

http://bugzilla.ximian.com/show_bug.cgi?id=76844

--- shadow/76844	2005-11-29 15:44:28.000000000 -0500
+++ shadow/76844.tmp.6054	2005-11-29 17:05:52.000000000 -0500
@@ -63,6 +63,47 @@
 }
 
 ------- Additional Comments From grendello at gmail.com  2005-11-29 15:44 -------
 I've just started playing with that and as the first thing I checked
 the old lockbits/unlockbits code - it works as expected, the data of
 the bitmap is correctly modified on unlock.
+
+------- Additional Comments From miguel at ximian.com  2005-11-29 17:05 -------
+Lockbits is the broken piece of code, this code does not use unsafe
+code, but instead uses Marshal.WriteByte and still produces the wrong
+result.
+
+The result should be a greenish square, instead we get a grey square
+on Mono
+
+using System;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.Runtime.InteropServices;
+
+class X {
+        static void Main ()
+        {
+                Bitmap b = new Bitmap(100, 100,
+PixelFormat.Format32bppArgb);
+                Graphics     g = Graphics.FromImage(b);
+                g.Clear(Color.Silver);
+                BitmapData bmData = b.LockBits (new Rectangle(0, 0,
+b.Width, b.Height),
+                                                ImageLockMode.ReadWrite,
+PixelFormat.Format24bppRgb);
+                        System.IntPtr Scan0 = bmData.Scan0;
+                        int nWidth = b.Width;
+                        int nHeight = b.Height;
+                        int p = 0;
+
+                        for(int y=0;y < nHeight;++y) {
+                                for(int x=0; x < nWidth; ++x ) {
+                                        Marshal.WriteByte (Scan0, y *
+nWidth * 3 + x * 3 + 1, 0xff);
+                                }
+                        }
+                b.UnlockBits(bmData);
+                b.Save ("s.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
+        }
+}
+


More information about the mono-bugs mailing list