我正在开发一个程序,需要修改屏幕上已经存在的内容。
所以我只有一个使用ID2D1Bitmap创建的pRenderTarget->CopyFromRenderTarget

我想要做的是将效果应用于该位图。效果只返回ID2D1Image,但我需要有一个ID2D1Bitmap

有没有办法做到这一点?

编辑1:

ID2D1Bitmap* myBitmap //the bitmap I want to apply the effect to
ID2D1Effect* effect = NULL;
pDeviceContext->CreateEffect(CLSID_D2D1Saturation, &effect);
effect->SetValue(D2D1_SATURATION_PROP_SATURATION, 0.0f);
effect->SetInput(0, myBitmap);

ID2D1Image* pImg = NULL;
effect->GetOutput(&pImg);


如果我投射此图像,则getPixelSize()会引发访问冲突。

最佳答案

我解决了很脏,但是可以用。

ID2D1Bitmap* convertImageToBitmap(ID2D1Image* pImg, D2D1_SIZE_U size)
{
    ID2D1Image* oldTarget = NULL;
    ID2D1Bitmap1* targetBitmap = NULL;

    //Create a Bitmap with "D2D1_BITMAP_OPTIONS_TARGET"
    D2D1_BITMAP_PROPERTIES1 bitmapProperties =
        D2D1::BitmapProperties1(
        D2D1_BITMAP_OPTIONS_TARGET,
        D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED)
    );
    pDeviceContext->CreateBitmap(size, 0, 0, bitmapProperties, &targetBitmap);

    //Save current Target, replace by ID2D1Bitmap
    pDeviceContext->GetTarget(&oldTarget);
    pDeviceContext->SetTarget(targetBitmap);
    //Draw Image on Target (if currently not drawing also call Begin/EndDraw)
    pDeviceContext->DrawImage(pImg);

    //Set previous Target
    pDeviceContext->SetTarget(oldTarget);

    oldTarget->Release();

    return targetBitmap;
}

10-04 11:56