WxWidgets 绘制具有不透明度的位图

发布于 2024-08-19 04:37:02 字数 211 浏览 3 评论 0原文

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

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

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

How can I draw a wxImage, or wxBitmap to a DC with opacity? It looks like its not possible with the standard DC or with wxGraphicsContext.

BeginLayer/EndLayer is not yet implemented in wxGraphicsContext which would have been one solution. GDI+ doesn't seem to support layers, so it would be non-trivial to add this.

The only solution seems to be to programmatically alter the alpha channel pixel-by-pixel?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无人问我粥可暖 2024-08-26 04:37:02
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 );
 }
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 );
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文