d2dlib icon indicating copy to clipboard operation
d2dlib copied to clipboard

Bitmap on Bitmap Transparency

Open sdreb3421 opened this issue 4 years ago • 3 comments

When using the DrawBitmap method to draw one bitmap over another, all semi-transparent pixels show up as fully opaque.

g.DrawBitmap(backImage, this.ClientRectangle); g.DrawBitmap(frontImage, new D2DRect(0, 0, frontImage.Width, frontImage.Height), 1, D2DBitmapInterpolationMode.Linear);

image

sdreb3421 avatar Aug 29 '21 17:08 sdreb3421

Did you have try the alpha channel option?

If your backImage and frontImage are GDI bitmaps, call drawBitmap and pass true to enable alpha channel.

g.DrawGDIBitmap(..., alpha: true, ...);

If your backImage and frontImage are Direct2D Bitmaps, pass true to enable alpha channel when you convert them.

var d2dbmp = Device.CreateBitmapFromGDIBitmap(..., useAlphaChannel: true);

jingwood avatar Aug 29 '21 23:08 jingwood

We are using Direct2D Bitmaps and the alpha channel is set to true.

If the alpha channel is set to false, all transparent pixels in the overlayed image are opaque. If set to true, the fully transparent pixels are transparent, but semi transparent pixels are fully opaque (incorrect layering).

For example, in the image above the coordinate system arrows are surrounded with semi transparent pixels that are showing up as fully opaque whitish pixels. When drawn with GDI+ these are not white.

sdreb3421 avatar Aug 31 '21 08:08 sdreb3421

I also have the same problem

d2phap avatar Jan 01 '22 16:01 d2phap