locked
It is possible to convert WriteableBitmap to ID2D1Bitmap RRS feed

  • Question

  • Hi,

    I'm developing Windows Phone 8.1 app (Universal app). 

    I wan't to convert WriteableBitmap  to ID2D1Bitmap.

    Is there any good way to convert?

    Many Thanks for hints

    Monday, August 4, 2014 7:44 AM

Answers

  • Hello,

    Sorry for the late reply. This should be relatively easy to do. You should be able to get the raw bits using "WriteableBitmap.PixelBuffer". You can then use "ID2D1RenderTarget::CreateBitmapFromWicBitmap" via "IWICImagingFactory::CreateStream" and "IWICStream::InitializeFromMemory" to load the raw bits into a new D2D bitmap object.

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Thursday, August 14, 2014 12:53 AM

All replies

  • I'll ask our DirectX guru to check this out.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, August 4, 2014 8:08 PM
  • Hi Matt,

    Details:

    I have an image (WriteableBitmap) and want to be able to render this image using ID2D1DeviceContext::DrawBitmap(); which means i need to convert this to a ID2D1Bitmap. 

    Many Thanks

    Wednesday, August 6, 2014 8:01 AM
  • Hello,

    I just returned from holiday. Do you still need help with this?

    Thanks,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, August 6, 2014 11:34 PM
  • Hi,

    Yes, i still need help. 

    Thursday, August 7, 2014 6:43 AM
  • Hi James,

    at the company I work for we also have that same problem. At this moment our solution circumvents this issue by first converting the WriteableBitmap to a PNG format using the Windows::Graphics::Imaging::BitmapEncoder class. Then we pass this PNG image stream to our Direct2D code which decodes it back using the IWICBitmapDecoder. Encoding the image just to decode it in the next step seems a bit inefficient to me.

    Surely there must be a way to pass the raw pixel data from WriteableBitmap to Direct2D? I'm looking forward to your answer James.

    Cheers, Janez

    Tuesday, August 12, 2014 10:28 AM
  • You can get to the backing image data of the WriteableBitmap by accessing the Pixels array that stores each pixel as a premultiplied ARGB value. I don't know if you can use that format directly in your texture. If you need to convert the format I would suggest to take a look at the Nokia Imaging SDK which allows you to define the colorformat that is to be used by a rendered Bitmap (you would use the WriteableBitmap as Source and use a Renderer to render to your target format). The raw pixel data of an Imaging SDK Bitmap can be read from the backing Buffer.

    Hope that info helps.

    Tuesday, August 12, 2014 10:45 AM
  • Hey Oliver,

    converting my WriteableBitmap to a different format using the Nokia Imaging SDK instead of the BitmapEncoder .NET provides, wouldn't solve my problem. I'm looking for a way to give Direct2D my raw pixel data directly. But thanks for you answer :-)

    Cheers, Janez

    Tuesday, August 12, 2014 11:43 AM
  • Hello,

    Sorry for the late reply. This should be relatively easy to do. You should be able to get the raw bits using "WriteableBitmap.PixelBuffer". You can then use "ID2D1RenderTarget::CreateBitmapFromWicBitmap" via "IWICImagingFactory::CreateStream" and "IWICStream::InitializeFromMemory" to load the raw bits into a new D2D bitmap object.

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Thursday, August 14, 2014 12:53 AM
  • I didn't mean to use the ImagingSDK instead of the BitmapEncoder but rather to use it if the premultiplied ARGB PixelFormat contained in the PixelBuffer was not suitable for a texture. You can use the ImagingSDK to convert to 16 bit, BGRA 32 bit, CMYK, etc. so I brought it up.

    Given James's reply however it seems that premultiplied ARGB is a valid PixelFormat for the D2D bitmap so no conversion is needed. I just added this post for completeness sake.

    Thursday, August 14, 2014 6:53 AM