且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何实现图标叠加

更新时间:2023-02-08 19:23:07

下面是一个例如在C#中,虽然我很抱歉它更多的是代码转储比如何做到这一点的解释。

Here's an example in C#, although I apologise its more of a code dump than an explanation of how to do it.

http://alski.net/post/2012/01/11/WPF-Icon-Overlays.aspx

最重要的一点就是这个,这需要视觉并将其转换成一个位图。该IconOverlay绑定到生成的位图。

The important bit is this which takes a Visual and converts it into a bitmap. The IconOverlay is bound to the generated bitmap.

 public static BitmapSource GenerateBitmapSource(Visual visual, double renderWidth, double renderHeight)
    {
        var bmp = new RenderTargetBitmap((int)renderWidth, (int)renderHeight, 96, 96, PixelFormats.Pbgra32);
        var dv = new DrawingVisual();
        using (DrawingContext dc = dv.RenderOpen())
        {
            dc.DrawRectangle(new VisualBrush(visual), null, new Rect(0, 0, renderWidth, renderHeight));
        }
        bmp.Render(dv);
        return bmp;
    }