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;
            }
  • 相关阅读:
    EntityFramework4.5使用Expression类创建动态查询及动态查询导航属性
    EF 5.0 帮助类
    EF异常:“System.InvalidOperationException”类型的未经处理的异常在 mscorlib.dll 中发生
    EF框架学习手记
    Entity Framework 学习
    C#特性-表达式树
    LINQ to SQL 运行时动态构建查询条件
    一点css 基础
    JQuery 判断复选框是否选中
    Asp.Net Server.MapPath()用法
  • 原文地址:https://www.cnblogs.com/quietwalk/p/3536186.html
Copyright © 2011-2022 走看看