小编Fol*_*der的帖子

将来自 model3dgroup 的 3D 模型的图像渲染为位图失败

我正在使用 C# WPF,并且尝试从 3D 模型渲染 2D 视图,我可以将其用作 ui 项目的预览图像。

为了实现这一目标,我尝试正确使用此类:

RenderTargetBitmap 类( https://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap(v=vs.110).aspx )

这就是我尝试使用它的方式:

更新后就无所谓了

public void SetModelImage()
    {
        RenderTargetBitmap bmp = new RenderTargetBitmap(200, 200, 96, 96, PixelFormats.Pbgra32);
        PngBitmapEncoder png = new PngBitmapEncoder();
        Viewport3D myViewport3d = new Viewport3D();
        ModelVisual3D myModelVisual3D = new ModelVisual3D();
        Model3DGroup myModel3DGroup = new Model3DGroup();
        GeometryModel3D myGeometryModel = new GeometryModel3D();
        this.previewModel = new PngBitmapEncoder();
        PerspectiveCamera myPCamera = new PerspectiveCamera();

        myModel3DGroup.Children.Add(this.content);// ajoute le modele
        myModelVisual3D.Content = myModel3DGroup;
        myModelVisual3D.Content = this.content;
        myViewport3d.Children.Add(myModelVisual3D);
        bmp.Render(myViewport3d);

        this.previewModel.Frames.Add(BitmapFrame.Create(bmp));

        string filepath = …
Run Code Online (Sandbox Code Playgroud)

c# wpf bitmap helix-3d-toolkit

5
推荐指数
1
解决办法
1516
查看次数

如何使用wrappanel处理选择事件

我目前正在使用C#WPF项目,我在几行中显示图像(蓝头)

在此输入图像描述

问题是我无法选择任何这些项目,我使用MVVM模式,因此后面的代码必须尽可能轻,我必须在xaml文件中执行操作.

所以我希望能够通过点击它们来选择图像,我试图使用像"IsMouseOver"这样的事件,但我只能改变整个包装而不是单个项目.

这是我使用的代码:

<Grid Grid.Row="1" Height="Auto">
        <Grid.Background>
            <LinearGradientBrush>
                <LinearGradientBrush.GradientStops>
                    <GradientStop Color="#252525" />
                </LinearGradientBrush.GradientStops>
            </LinearGradientBrush>
        </Grid.Background>
        <ItemsControl Background="Transparent" Foreground="AntiqueWhite" BorderBrush="Transparent"
                 HorizontalContentAlignment="Stretch" ItemsSource="{Binding Source={x:Static Context:Session.CurrentSession}, Path=CurrentProject.Models}">
            <ItemsControl.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Delete" Command="{Binding DeleteModel3DCommand}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}"/>
                </ContextMenu>                    
            </ItemsControl.ContextMenu>
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <i:InvokeCommandAction Command="{Binding SelectModel3DCommand}" CommandParameter="{Binding Path=SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Image Source="/McKineap;component/Resources/Images/logo-mckineap.png" Height="100"/>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel/>   
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>
    </Grid>
Run Code Online (Sandbox Code Playgroud)

我会就你在我的报道中定义选择事件的正确方法提出任何建议,谢谢你的时间!

c# wpf mvvm

3
推荐指数
1
解决办法
1329
查看次数

标签 统计

c# ×2

wpf ×2

bitmap ×1

helix-3d-toolkit ×1

mvvm ×1