我有 2 个位图(前景和背景),我需要将它们叠加在一起以形成一个新的位图并将其用作按钮的 ImageBrush。代码看起来像这样(Windows 8.1 商店应用程序):
WriteableBitmap foregroundBitmap = GetForegroundBitmap();
WriteableBitmap backgroundBitmap = GetBackgroundBitmap();
ImageBrush imageBrush = new ImageBrush();
imageBrush.ImageSource = Overlay(foregroundBitmap, backgroundBitmap);
Button button = new Button();
button.Background = imageBrush;
如何实现上面的 Overlay(...) 方法?
我试过了:
backgroundBitmap.Blit(
new Rect(0, 0, backgroundBitmap.PixelWidth, backgroundBitmap.PixelHeight),
foregroundBitmap,
new Rect(0, 0, foregroundBitmap.PixelWidth, foregroundBitmap.PixelHeight),
WriteableBitmapExtensions.BlendMode.None);
但它不起作用(使用 BlendedMode None 或 Additive)。
谢谢。