Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

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

closed
nobody
None
5
2011-05-26
2011-05-25
Brendan Simon
No

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 ??

Discussion

    • status: open --> closed
     
  • 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);
    bitmapSerialization.Flush();
    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).