【问题标题】:WxWidgets draw a bitmap with opacityWxWidgets 绘制一个不透明的位图
【发布时间】:2010-01-19 20:16:15
【问题描述】:

如何将 wxImage 或 wxBitmap 绘制到具有不透明度的 DC?使用标准 DC​​ 或 wxGraphicsContext 似乎是不可能的。

BeginLayer/EndLayer 尚未在 wxGraphicsContext 中实现,这将是一种解决方案。 GDI+ 似乎不支持图层,因此添加它并非易事。

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

【问题讨论】:

  • 希望我能提供帮助,但我对 wxWidgets 处理不透明度有自己的问题...

标签: gdi+ wxwidgets


【解决方案1】:
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 );
 }

【讨论】:

  • 对不起,我错过了你的答案。一切顺利。
猜你喜欢
  • 2016-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多