【问题标题】:Overlay bitmaps (writeablebitmap etc.) in windows store appWindows 商店应用程序中的叠加位图(writeablebitmap 等)
【发布时间】:2014-01-08 00:34:46
【问题描述】:

我有 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)。

谢谢。

【问题讨论】:

    标签: c# windows-store-apps windows-8.1 writeablebitmap blit


    【解决方案1】:

    试试这个

     <Window.Resources>
        <BitmapImage x:Key="image1" UriSource="DefaultImage.png"></BitmapImage>
        <BitmapImage x:Key="image2" UriSource="ImageRoation.png"></BitmapImage>
     </Window.Resources>
    
    <Button Height="200" Width="200">
        <Grid Height="200" Width="200">
            <Grid.Background>
                <ImageBrush ImageSource="{StaticResource image1}" Stretch="Fill" ></ImageBrush>
            </Grid.Background>
            <Grid Margin="5" Width="50" Height="50"> 
                <Grid.Background>
                    <ImageBrush ImageSource="{StaticResource image2}" Stretch="Fill"></ImageBrush>
                </Grid.Background>
            </Grid>
        </Grid>
    </Button>
    

    【讨论】:

    • 感谢您的样品。实际上,我在运行时加载了大约 50 个像这样的各种按钮,需要用代码而不是 XAML 来完成。无论如何,我在我的代码中发现了问题,现在“blit”可以工作了。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多