In D2D, is there a way to create a gradient brush which uses a custom path geometry as its start/stop points? I can do the trivial way of creating a different brush for each step of the path and rendering that as a separate path with that brush, but I am looking for something that won’t kill performance.
Thanks!
What you want is an equivalent to GDI+’s PathGradient, which simply doesn’t exist in Direct2D.
As a workaround, you may try using GDI+ to render what you need into a bitmap, and then draw that with Direct2D. This won’t be hardware accelerated, and the bitmap sharing between GDI+ and Direct2D is a little clumsy, but it would at least work. You would create an ID2D1Bitmap with
ID2D1RenderTarget::CreateBitmap(), then lock the GDI+ Bitmap, then useID2D1Bitmap::CopyFromMemory()with the values from the GDI+ BitmapData.If you are using a software render target, you can also use
ID2D1RenderTarget::CreateSharedBitmap()which would let you skip the memoroy copying. It would require you to first wrap the GDI+ BitmapData (aka “the locked GDI+ Bitmap”) with an IWICBitmapLock implementation of your own (it’s not difficult, but certainly clumsy).