How to save ID2D1Bitmap to PNG file did not help me.
I'm working with Direct2D.
I want to save a ID2D1**Hwnd**RenderTarget *m_pRenderTarget
to file as bmp or png etc.
But the sample I found on MSDN use ID2D1RenderTarget
.
In my case I drawn my figure in m_pRenderTarget, I used the method ID2D1Bitmap::CopyFromRenderTarget (...)
to get an ID2D1Bitmap.
After that, to use the saving function bellow, I have to convert the ID2D1Bitmap
I got to IWICBitmap
. Because the function bellow doesn't use ID2D1Bitmap
...
I did not found yet how to do this.
thanks.
if (SUCCEEDED(hr))
{
//
// Save image to file
//
hr = pWICFactory->CreateStream(&pStream);
}
WICPixelFormatGUID format = GUID_WICPixelFormatDontCare;
if (SUCCEEDED(hr))
{
static const WCHAR filename[] = L"output.png";
hr = pStream->InitializeFromFilename(filename, GENERIC_WRITE);
}
if (SUCCEEDED(hr))
{
hr = pWICFactory->CreateEncoder(GUID_ContainerFormatPng, NULL, &pEncoder);
}
if (SUCCEEDED(hr))
{
hr = pEncoder->Initialize(pStream, WICBitmapEncoderNoCache);
}
if (SUCCEEDED(hr))
{
hr = pEncoder->CreateNewFrame(&pFrameEncode, NULL);
}
if (SUCCEEDED(hr))
{
hr = pFrameEncode->Initialize(NULL);
}
if (SUCCEEDED(hr))
{
hr = pFrameEncode->SetSize(sc_bitmapWidth, sc_bitmapHeight);
}
if (SUCCEEDED(hr))
{
hr = pFrameEncode->SetPixelFormat(&format);
}
if (SUCCEEDED(hr))
{
hr = pFrameEncode->WriteSource(pWICBitmap, NULL);
}
if (SUCCEEDED(hr))
{
hr = pFrameEncode->Commit();
}
if (SUCCEEDED(hr))
{
hr = pEncoder->Commit();
}
to explain easily, I already had a Direct2D code and my drawing image is hold on my ID2D1HwndRenderTarget. I want to save the drawn image hold by my ID2D1HwndRenderTarget on disk.
the sample I found create a new IWICBitmap, and with
pD2DFactory->CreateWicBitmapRenderTarget(pWICBitmap,D2D1::RenderTargetProperties(),&pRT);
create a new ID2D1RenderTarget to draw. After drawing operations, it wrote the bitmap image
hr = pFrameEncode->WriteSource(pWICBitmap, NULL);
In my case I don't know how to put the image from my ID2D1HwndRenderTarget to IWICBitmap... to write it. someone have a clue with how to bind ID2D1HwndRenderTarget and IWICBitmap