[Gtk-sharp-list] Load a Bitmap in ImageSurface

Saeed shahbazi saeed.shahbazi at gmail.com
Tue Oct 15 00:26:33 UTC 2013


Hi all,

I'm using Mono and .Net 2 and I want to load a System.Drawing.Image image
to ImageSurface for CairoGraphics. All my efforts led to fussy images but
the one as follows:
const string TmpFileName = "cairo_tmp.png";
image.Save(TmpFileName, ImageFormat.Png);
var imageSurface = new ImageSurface(TmpFileName);
imageSurface.Show(this.m_internalContext, x, y);
imageSurface.Destroy();

However, I don't want to write it to disk and load it again. Is there any
other solution?

The other thing I tried is as follows:

           Bitmap clone = new Bitmap(image.Width, image.Height,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            using (System.Drawing.Graphics gr =
System.Drawing.Graphics.FromImage(clone))
            {
                gr.DrawImage(image, new Rectangle(0, 0, clone.Width,
clone.Height));
            }

            var ms = new MemoryStream();
            image.Save(ms, ImageFormat.Bmp);
            var imageSurface = new ImageSurface(ms.ToArray(),
Format.ARGB32, image.Width, image.Height, image.Width * 4);
            this.m_internalContext.Antialias = Antialias.None;
            imageSurface.Show(this.m_internalContext, destRect.X,
destRect.Y);
            imageSurface.Destroy();
            ms.Dispose();

I think the problem is related to the formatting. my black pictures with
white letters inside become green pictures, cut in half which are rotated.

Cheers,
S.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20131015/b7b6b7d9/attachment.html>


More information about the Gtk-sharp-list mailing list