Search code examples
c#directxdirect2dsharpdx

How to get pixel color of Direct2D bitmap on SharpDX


I use SharpDX and I don't understand how to get pixel color at bitmap. I found CopySubresourceRegion method, but it working on Direct3D. I've strange idea:

I can create RenderForm and drawing my bitmap on form. Then get graphics of form. Then create bitmap via "new Bitmap(width, height, graphics)". And then get pixel color from new bitmap;


Solution

  • If you are targeting Direct2D 1.1 (or higher), then you can use the ID2D1Bitmap1::Map method. This will require that you set D2D1_BITMAP_OPTIONS_CPU_READ and D2D1_BITMAP_OPTIONS_CANNOT_DRAW flags on the bitmap when creating it.