zoukankan      html  css  js  c++  java
  • ImageEdit 加载图片

    从本地加载图片

     <dxe:ImageEdit Name="iePortrait" Height="120" Width="100" 
                                       Stretch="Uniform"  ToolTip="{DynamicResource ResourceKey=ResPortrait}" 
                                           Cursor="Hand" ShowMenu="False"></dxe:ImageEdit>
      public class OpenPictureCommand : Command<RegistrationEditor>
            {
                protected override void Executed(object sender, ExecutedRoutedEventArgs e)
                {
                    System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
                    //EventBinder.BindControls(ofd); // added
                    ofd.Filter = "(*.jpg)|*.jpg";
                    if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        string fileName = ofd.FileName;
                        Console.WriteLine(fileName);
                        BitmapImage img = new BitmapImage(new Uri(fileName));
                        Owner.iePortrait.EditValue = img;
                    }
                }
            }

    Save :

      public string BitmapimageToBase64(BitmapImage bi)
            {
                if (bi == null) return "";
                byte[] b = this.getJPGFromImageControl(bi);
                string base64String = Convert.ToBase64String(b);
                return base64String;
            }
    
            public byte[] getJPGFromImageControl(BitmapImage imageC)
            {
                MemoryStream memStream = new MemoryStream();
                JpegBitmapEncoder encoder = new JpegBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(imageC));
                encoder.Save(memStream);
                return memStream.GetBuffer();
            }

    Load:

     iePortrait.EditValue = this.Base64ToBitmapImage(selectedPortrait.Portrait);
      public BitmapImage Base64ToBitmapImage(string str)
            {
                if (str == null || str=="") return null;
                byte[] imageBytes = Convert.FromBase64String(str);
                BitmapImage bitmapImage = new BitmapImage();
                MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = ms;
                bitmapImage.EndInit();
                return bitmapImage;
            }
  • 相关阅读:
    关于发布版本号管理
    WWF
    C#编码规范和命名规则
    使用正则表达式更改编译版本号
    .net2005登录控件
    读取web.config自定义配置节
    在SQL SERVER 2005 中使用XML
    CVSNT用户权限配置
    共享鼠标
    《Ajax基础教程》
  • 原文地址:https://www.cnblogs.com/quietwalk/p/3536186.html
Copyright © 2011-2022 走看看