I'm generating bitmaps in the Code and want to display it on the GUI. But the <ImageBrush>
is not showing them as BitmapSource/ImageSource
. Just like as an invisible image in the 3D part.
On the <Image>
(not the 3D part) it shows as wanted.
I also tried to create the DiffuseMaterial
and ImageBrush
in the codebehind and bind them directly into <h:RectangleVisual3D>
as Material
.
And tried to use <VisualBrush>
instead of <ImageBrush>
with <Image>
as child in XAML.
The following Code reproduce the issue for my case:
MainWindow.xaml
<Window x:Class="WPF3DTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPF3DTest"
xmlns:h="http://helix-toolkit.org/wpf"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<h:HelixViewport3D Grid.Row="0">
<h:DefaultLights />
<h:RectangleVisual3D Length="100" Width="100">
<h:RectangleVisual3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<ImageBrush Opacity="1" ImageSource="{Binding Image}" />
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</h:RectangleVisual3D.Material>
</h:RectangleVisual3D>
</h:HelixViewport3D>
<Image Grid.Row="1" Source="{Binding Image}" />
</Grid>
</Window>
MainWindow.xaml.cs
namespace WPF3DTest
{
public partial class MainWindow : Window
{
public ImageSource Image { get; set; }
public MainWindow()
{
InitializeComponent();
DataContext = this;
Image = new BitmapImage(new Uri("C:\\TypenschildDirectory\\Graphic\\laufrichtung2.png"));
Image.Freeze();
}
}
}
The new BitmapImage(new Uri(...))
is a test in my case. But for my purpose it's generated bitmaps by using Imaging.CreateBitmapSourceFromHBitmap(...)
.