.net 如何从图像(BMP/JPEG/PNG)创建DrawingBrush?

.net 如何从图像(BMP/JPEG/PNG)创建DrawingBrush?,.net,wpf,drawingbrush,.net,Wpf,Drawingbrush,我需要将DrawingBrush传递给第三方DLL中的一个方法,该DLL在应用程序的某个地方显示一个图像。我不能修改这个 我需要从BMP图像创建一个画笔。 我试过了,但没用 任何帮助都将不胜感激。应该可以 <Window x:Class="WpfApplication9.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.m

我需要将DrawingBrush传递给第三方DLL中的一个方法,该DLL在应用程序的某个地方显示一个图像。我不能修改这个

我需要从BMP图像创建一个画笔。 我试过了,但没用

任何帮助都将不胜感激。

应该可以

<Window x:Class="WpfApplication9.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" >
<Rectangle Height="100" Width="100">

    <Rectangle.Fill>
        <DrawingBrush>
            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <GeometryDrawing>
                        <GeometryDrawing.Brush>
                            <ImageBrush ImageSource="IC23839.jpg"  />
                        </GeometryDrawing.Brush>
                        <GeometryDrawing.Geometry>
                            <RectangleGeometry Rect="0,0 100,100" />
                        </GeometryDrawing.Geometry>

                    </GeometryDrawing>

                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>

    </Rectangle.Fill>

</Rectangle>
它应该会起作用

<Window x:Class="WpfApplication9.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" >
<Rectangle Height="100" Width="100">

    <Rectangle.Fill>
        <DrawingBrush>
            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <GeometryDrawing>
                        <GeometryDrawing.Brush>
                            <ImageBrush ImageSource="IC23839.jpg"  />
                        </GeometryDrawing.Brush>
                        <GeometryDrawing.Geometry>
                            <RectangleGeometry Rect="0,0 100,100" />
                        </GeometryDrawing.Geometry>

                    </GeometryDrawing>

                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>

    </Rectangle.Fill>

</Rectangle>