zoukankan      html  css  js  c++  java
  • 在winform中使用wpf窗体

    在winform项目,通过引用dll可以添加WPF窗体,如下

    但是如果直接在winform的项目中添加wpf窗体还是有部分问题,图片的显示

    直接在XAML界面中用Source属性设置图片会出现错误。必须通过后台代码的方式来实现。

      image1.Source = GetImageIcon(global::Com.JunXinEastern.Jcj.Properties.Resources.loginImg);
    
     Image image = new Image();
                image.Source = GetImageIcon(global::Com.JunXinEastern.Jcj.Properties.Resources.login_csyj1);
                ImageBrush ib = new ImageBrush();
                ib.ImageSource = image.Source;
                grid1.Background = ib;
    private static BitmapImage GetImageIcon(System.Drawing.Bitmap bitmap)
            {
                BitmapImage bitmapImage = new BitmapImage();
    
                try
                {
    
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    bitmap.Save(ms, bitmap.RawFormat);
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = ms;
                    bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                    bitmapImage.EndInit();
                    bitmapImage.Freeze();
    
    
                }
                catch (Exception ex)
                {
    
                    //Utilities.ShowExceptionMessage(ex);
                }
    
                return bitmapImage;
            }

    使用的winform项目中Resources.resx资源中的图片,这里图片还要求是png格式的才能成功加载,jpeg的则不行。

  • 相关阅读:
    shell test条件判断
    shell 变量
    shell 流程结构
    shell 正则表达式
    shell脚本常用参数
    snmp 简单的网络管理协议
    linux
    nmap
    git 基础操作
    linux 下 svn 更新代码
  • 原文地址:https://www.cnblogs.com/KQNLL/p/9208810.html
Copyright © 2011-2022 走看看