繁体   English   中英

Windows应用商店中的叠加位图(writeablebitmap等)

[英]Overlay bitmaps (writeablebitmap etc.) in windows store app

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

谢谢。

尝试这个

 <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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM