【问题标题】:Overlay two bitmap images in WPF在 WPF 中叠加两个位图图像
【发布时间】:2011-03-22 02:37:14
【问题描述】:

我需要叠加两个图像(例如,具有透明度的 JPEG 和 PNG)。

输入: - JPEG图像 - PNG图像

输出: - 应用了 PNG 的 JPEG 图像。

最好的方法是什么?

提前感谢您的回复和提示!

干杯

【问题讨论】:

    标签: c# wpf bitmap overlay


    【解决方案1】:

    您可以像这样使用 DrawingGroup:

    var group = new DrawingGroup();
    group.Children.Add(new ImageDrawing(new BitmapImage(new Uri(@"...\Some.jpg", UriKind.Absolute)), new Rect(0, 0, ??, ??)));
    group.Children.Add(new ImageDrawing(new BitmapImage(new Uri(@"...\Some.png", UriKind.Absolute)), new Rect(0, 0, ??, ??)));
    
    MyImage.Source = new DrawingImage(group);
    

    【讨论】:

    • 关于如何将其转换回 BitmapImage 的任何想法?
    • @Mohib:我不知道。您需要有一个 BitmapSource 或一个 Stream 才能使用编码器,但我找不到从 DrawingImage 或 DrawingGroup 到 BitmapSource 的任何机制。尝试将此作为一个新问题提出。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-29
    • 1970-01-01
    • 1970-01-01
    • 2011-07-05
    • 2016-07-20
    • 2022-11-04
    相关资源
    最近更新 更多