#2 Converting wx.Bitmap (or wx.Image) to System.Drawing.Bitmap


How do I convert wx.Bitmap and/or wx.Image to/from System.Drawing.Bitmap ??
I'm using and image processing library called AForge.net which seems to apply filters to System.Drawing.Bitmaps. I'm not sure if I can use wx.Bitmaps or not, but what I do know is that wx.StaticBitmap will not display System.Drawing.Bitmaps.

I'm open to any suggestions ??


  • Harald Meyer auf\'m Hofe

    • status: open --> closed
  • Harald Meyer auf\'m Hofe

    System.Drawing.Bitmap can be converted into a WX.Bitmap using serilization and deserialization. The following sample writes a System.Drawing.Bitmap into a memory stream, reads the bytes from this stream, and creates a WX.Image from this bytes.

    WX.Bitmap wxBitmapFromFxBitmap;
    System.Drawing.Bitmap fxBitmap = new System.Drawing.Bitmap(imgPath + "fxbitmaptest.bmp");
    using (System.IO.MemoryStream bitmapSerialization = new System.IO.MemoryStream())
    fxBitmap.Save(bitmapSerialization, System.Drawing.Imaging.ImageFormat.Png);
    byte[] bitmapBytes = bitmapSerialization.ToArray();
    wxBitmapFromFxBitmap=new Bitmap(new Image(bitmapBytes, BitmapType.Png));
    BitmapButton wxBitmapFromFxBitmapButton = new BitmapButton(panel, wxBitmapFromFxBitmap, new Point(250, 160), new Size(40, 40), WindowStyles.ButtonAutoDraw);
    wxBitmapFromFxBitmapButton.ToolTip = "This bitmap has been converted from a System.Drawing.Bitmap instance.";

    This code has been added to the controls sample. Please note, that notation may differ from 0.92 notation (e.g. WX.Bitmap <=> wx.Bitmap).


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks