• WPF中实现图片文件转换成Visual对象,Viewport3D对象转换成图片


    1、图片文件转换成Visual对象

            private Visual CreateVisual(string imageFileName)
            {
                BitmapImage bmp = new BitmapImage(new Uri(imageFileName));


                Image img = new Image();
                img.Width = 100;
                img.Source = bmp;

                Border outBordre = new Border();
                outBordre.BorderBrush = Brushes.White;
                outBordre.BorderThickness = new Thickness(0.5);
                outBordre.Child = img;


                return outBordre;
            }

    2、Viewport3D对象转换成图片

    private Image ConvertViewport3DToImage(Viewport3D vp)
            {
                Grid grid = new Grid();
                grid.Children.Add(vp);

                RenderTargetBitmap bitmap = CreateImageBrushFromVisual(grid);

                Image img = new Image();
                img.Source = bitmap;
                img.Stretch = Stretch.None;

                img.Width = vp.Width;
                img.Height = vp.Height;

                return img;
            }

            private RenderTargetBitmap CreateImageBrushFromVisual(FrameworkElement element)
            {
                RenderTargetBitmap bitmapImage =
                    new RenderTargetBitmap((int)(element.Width), (int)(element.Height), 96, 96, PixelFormats.Pbgra32);

                bitmapImage.Render(element);

                return bitmapImage;
            }

  • 相关阅读:
    Mybatis与Hibernate概述
    Linux命令中:rsync和scp之间的区别
    更改了ssh文件下,还没有权限
    karaf 控制台 常用linux指令(2)
    karaf 控制台 常用linux指令(1)
    POM文件详解(2)
    POM文件详解(1)
    maven配置parent pom查找策略
    排序算法性能比较
    Eclipse下用NDK编译生成so文件
  • 原文地址:https://www.cnblogs.com/zhihai/p/2611146.html
Copyright © 2020-2023  润新知