如何绘制没有背景颜色的多图像/位图?

时间:2018-04-21 04:37:17

标签: c++ blend direct2d

我有多个图像/位图,其背景为白色,现在我想绘制这些图像以逐个渲染目标而没有复制白色。我试图实现:

  1. SetPrimitiveBlend(D2D1_PRIMITIVE_BLEND_MIN),参考D2D1_PRIMITIVE_BLEND enumeration,但是延迟绘制的图像的非白色像素不会覆盖之前的图像,交叉点会显示另一种颜色。

    _deviceContext->SetPrimitiveBlend(D2D1_PRIMITIVE_BLEND_MIN);
    
    _deviceContext->BeginDraw();  
    _deviceContext->Clear(D2D1::ColorF(D2D1::ColorF::White));  
    _deviceContext->DrawBitmap(Bkg, D2D1::RectF(0, 0, _width, _height), 1.0);  
    _deviceContext->DrawBitmap(Img1, D2D1::RectF(0, 0, _width, _height), 1.0);  
    _deviceContext->DrawBitmap(Img2, D2D1::RectF(0, 0, _width, _height), 1.0);  
    hr = _deviceContext->EndDraw();
    
  2. 然后我尝试了另一种方法作为示例Direct2D composite effect modes sample,它只适用于一个前景图像和一个背景图像。但我需要绘制多个前景图像。

    _deviceContext->CreateEffect(CLSID_D2D1Blend, &_EffectBlend);  
    _deviceContext->CreateEffect(CLSID_D2D1ColorMatrix, &_EffectFore);  
    _deviceContext->CreateEffect(CLSID_D2D1ColorMatrix, &_EffectBack);  
    _EffectBlend->SetValue(D2D1_BLEND_PROP_MODE, D2D1_BLEND_MODE_DARKER_COLOR);     
    _EffectBlend->SetInputEffect(0, _EffectBack);  
    _EffectBlend->SetInputEffect(1, _EffectFore);     
    _EffectBack->SetInput(0, Bkg);    
    _EffectFore->SetInput(0, Img1);   
    
    _deviceContext->BeginDraw();  
    _deviceContext->Clear(D2D1::ColorF(D2D1::ColorF::White));  
    _deviceContext->DrawImage(_EffectBlend, D2D1_INTERPOLATION_MODE_LINEAR);  
    _deviceContext->EndDraw();    
    

0 个答案:

没有答案