代码之家  ›  专栏  ›  技术社区  ›  hplbsh

wxwidgets绘制不透明度位图

  •  0
  • hplbsh  · 技术社区  · 15 年前

    如何绘制wximage或wxbitmap到不透明度的dc?在标准DC或WXgraphicContext中似乎不可能。

    beginlayer/endlayer尚未在wxgraphicContext中实现,而wxgraphicContext是一种解决方案。gdi+似乎不支持层,因此添加它是非常重要的。

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

    1 回复  |  直到 15 年前
        1
  •  2
  •   Denys Usynin    15 年前
    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 );
     }