Merge an ImageBrush and a SolidColorBrush ? (as a Background of a Canvas)

对着背影说爱祢 提交于 2020-04-11 06:22:31

问题


I have an ImageBrush and a SolidColorBrush. The thing is that I, now, want to set my canvas background with these properties.

I can easily set my background to either my ImageBrush or my SolidColorBrush but can I do a sort of merge ? The thing is that my ImageBrush.Stretch is set to Uniform so I can see the background color behind ! (It wouldn't be the case with "Fill")

Now, Brush is an abstract class so the solution I image is to extend it but that really is a lot of work for a thing that sounds simple and common to me...

Isn't there any other solution ?


回答1:


What about this, although it has the drawback that the image's absolute size and, more important, the aspect ratio is ignored. But it may give you a hint.

<Canvas>
    <Canvas.Background>
        <DrawingBrush>
            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <GeometryDrawing Brush="Orange">
                        <GeometryDrawing.Geometry>
                            <RectangleGeometry Rect="0,0,1,1"/>
                        </GeometryDrawing.Geometry>
                    </GeometryDrawing>
                    <ImageDrawing ImageSource="C:\Users\Public\Pictures\Sample Pictures\Desert.jpg" Rect="0.2,0.2,0.6,0.6" />
                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>
    </Canvas.Background>
</Canvas>


来源:https://stackoverflow.com/questions/9196194/merge-an-imagebrush-and-a-solidcolorbrush-as-a-background-of-a-canvas

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!