Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

wpf

brush

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 ?

like image 529
Guillaume Slashy Avatar asked Nov 21 '25 18:11

Guillaume Slashy


1 Answers

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>
like image 198
Clemens Avatar answered Nov 23 '25 07:11

Clemens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!