image - How to save ID2D1Bitmap to PNG file -


text "itemprop =" text ">

I encountered a problem when trying to save the PNG file to ID2D1Bitmap (that was created from ID2D1HwndRenderTarget). Output image is empty with just white color. The HRESULT function returns from the call (Andrew) -2323238894.

Thanks for any help

Here is my code:

  HRESULT CImageUtil :: SaveBitmapToFile (PCWSTR uri, ID2D1Bitmap * pBitmap, ID2D1RenderTarget * PRenderTarget) {HRESULT hr = S_OK; ID2D1Factory * pD2DFactory = NULL; IWCBitmap * PidBalbitmap = Faucet; ID2D1RenderTarget * pRT = NULL; IWIC Bitmap Encoder * PAncoder = Faucet; IWICBITMFFrame encode * PFRAMEAcode = faucet; IWICStream * pStream = NULL; If (SUCCEEDED (hour)) {hours = D2D1CreativeFactory (D2D1_FACTORY_TYPE_SINGLE_THREADED, & amp; pD2DFactory); } // // IWICBitmap and RT / UINT sc_bitmapWidth = pBitmap- & gt; GetSize () Width; UINT sc_bitmapHeight = pBitmap- & gt; GetSize () Height; If (SUCCEEDED (hour)) {hours = m_pWICFactory-> CreateBitmap (sc_bitmapWidth, sc_bitmapHeight, GUID_WICPixelFormat32bppPBGRA, WICBitmapCacheOnLoad, & amp; pWICBitmap); } If (SUCCEEDED (HR)) {D2D1_RENDER_TARGET_PROPERTIES rtProps = D2D1 :: RenderTreazapoPorte (); RtProps.pixelFormat = D2D1 :: PixelFormat (DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED); RtProps.type = D2D1_RENDER_TARGET_TYPE_DEFAULT; RtProps.usage = D2D1_RENDER_TARGET_USAGE_NONE; Hr = pD2DFactory-> CreateWicBitmapRenderTarget (pWIC bitmap, RTPPS, and PRT); } If (SUCCEEDED (HR)) // // Present in Bitmap- // PRT-> Start scare (); PRT- & gt; Clear (D2D1 :: Color (D2D1 :: Color :: White)); PRT- & gt; DrawBitmap (pBitmap); PRT- & gt; EndDraw (); } Save (// SUCCEEDED (HR)) // // file to // hr = m_pWICFactory-> CreateStream (& pStream); } WICPixelFormatGUID Format = GUID_WICPixelFormat32bppPBGRA; If (SUCCEEDED (HR)) {hr = pStream-> Early form filename (Yuri, GENERIC_WRITE); } If (SUCCEEDED (hour)) {hours = m_pWICFactory-> CreateEncoder (GUID_ContainerFormatPng, zero, & amp; pEncoder); } If (SUCCEEDED (HR)) {hr = pEncoder-> gt; Start (pStream, WICbitmapEncoderNoCache); } If (SUCCEEDED (HR)) {hr = pEncoder-> CreateNewFrame (& amp; pFrameEncode, NULL); } If (SUCCEEDED (HR)) {hr = pFrameEncode-> Start (NULL); } If (SUCCEEDED (HR)) {hr = pFrameEncode-> SetSize (sc_bitmapWidth, sc_bitmapHyight); } 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 (); } Safe Release (and PD2DFFarina); SafeRelease (& amp; pWICBitmap); SafeRelease (& PRT); SafeRelease (& amp; pEncoder); SafeRelease (& amp; pFrameEncode); SafeRelease (& amp; pStream); Returns HR; }    

How do you know that you have an error, because you have errors Swallow and will continue instead of logging where they will come? You get a non-zero Herslut, so first time it shows which function it comes after adding printf or fprintf after each function call. And you have a clear error in the block:

  if presented in SUCCEEDED (HR) // // bitmap; // PRT-> Start (fear); PRT- & gt; Clear (D2D1 :: Color (D2D1 :: Color :: White)); PRT- & gt; DrawBitmap (pBitmap); PRT- & gt; EndDraw (); } If (SUCCEEDED (HR))   

If you do not bother to assign an HR anywhere, you will not even know that any of them is getting the error or not. Obviously, clean () and last PNG writing work is fine, because you get a good file, so it's one of the draftmap or bitmap creation calls which is failing.

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -