WxWidgets使用不透明度绘制位图

时间:2010-01-19 20:16:16

标签: gdi+ wxwidgets

如何将wxImage或wxBitmap绘制为具有不透明度的DC?看起来使用标准DC或使用wxGraphicsContext是不可能的。

BeginLayer / EndLayer尚未在wxGraphicsContext中实现,这本来就是一个解决方案。 GDI +似乎不支持图层,因此添加它是非常重要的。

唯一的解决方案似乎是以编程方式逐个像素地改变alpha通道?

1 个答案:

答案 0 :(得分:2)

void YourCustomWindow::OnPaint( wxPaintEvent& event ) {
  wxPaintDC dc(this);
  wxImage image( width, height ); 
  image.InitAlpha();
  unsigned char* imgdata = img.GetData();
  unsigned char* imgalpha = img.GetAlpha();


  // manipulate raw memory buffers to populate
  // them with whatever image you like.
  // Putting zeros everywhere will create a fully
  // transparent image.


     // almost done, but not quite... 
     // wxDC can only draw wxBitmaps, not wxImage,
     // so one last step is required
  //
  wxBitmap bmp( image );
  dc.DrawBitmap( bmp, 0, 0 );
 }