[Mono-dev] Bug in System.Drawing or libgdiplus
Bernd Amend
amend at fbihome.de
Sat Jan 27 16:27:27 EST 2007
Hi,
I have a problem with Mono programs that use System.Drawing, on Gentoo
(x86, x86_64) or with the Linux Installer with mono 1.2.2.1 and
libgdiplus 1.2.2 or 1.2.1.
On Windows with .Net 2.0 and Mono 1.2.2.1 and Ubuntu 6.10 with Mono
1.1.13.6 and and Gentoo with Mono 1.13.8.1 and libgdiplus 1.1.13.2 the
created images testimage-invalid.png and testimage-valid.png are correct
and yellow.
With Mono 1.2.2.1 the image testimage-valid.png is yellow, after the
bitmap is locked again for readwrite the bitmap is crap see
testimage-invalid.png.
You have to compile it with "mcs /unsafe /r:System.Drawing main.cs" and
start the application with mono main.exe.
It creates the images testimage-valid.png and testimage-invalid.png.
If I create an image with PixelFormat.Format32bpp Rgb or Argb the
problem doesn't occurs. I think this is a Bug in libgdiplus or cairo but
i am not sure.
main.cs :
using System;
using System.Drawing;
using System.Drawing.Imaging;
class MainClass
{
public static void Main(string[] args)
{
Bitmap bitmap = new Bitmap(100,100);
BitmapData bmData = bitmap.LockBits(new
Rectangle(0,0,bitmap.Width,bitmap.Height),
ImageLockMode.ReadWrite,PixelFormat.Format24bppRgb);
unsafe {
byte *imgPtr = (byte*)(bmData.Scan0);
for( int i = 0 ; i < bmData.Height ; i ++ ) {
for( int j = 0 ; j < bmData.Width ; j ++ ) {
imgPtr[0] = 0;
imgPtr[1] = 255;
imgPtr[2] = 255;
imgPtr += 3;
}
imgPtr += bmData.Stride - bmData.Width * 3;
}
}
bitmap.UnlockBits(bmData);
bitmap.Save("testfile-valid.png",ImageFormat.Png); // imaged is
saved perfect
bmData = bitmap.LockBits(new
Rectangle(0,0,bitmap.Width,bitmap.Height),
ImageLockMode.ReadWrite,PixelFormat.Format24bppRgb); // it seams the
problem occurs here
bitmap.UnlockBits(bmData);
bitmap.Save("testfile-invalid.png",ImageFormat.Png); // image is
incorrect
}
}
The same problem occurs here:
(mcs /r:System.Drawing main.cs)
using System;
using System.Drawing;
using System.Drawing.Imaging;
class MainClass
{
public static void Main(string[] args)
{
Bitmap bitmap = new Bitmap("image.jpg");
BitmapData bmData = bitmap.LockBits(new
Rectangle(0,0,bitmap.Width,bitmap.Height),
ImageLockMode.ReadWrite,PixelFormat.Format24bppRgb);
bitmap.UnlockBits(bmData);
bitmap.Save("image.png",ImageFormat.Png);
}
}
Regards
Bernd Amend
More information about the Mono-devel-list
mailing list