ImageEdit 加载图片

从本地加载图片

 <dxe:ImageEdit Name="iePortrait" Height="120" Width="100" 
                                   Stretch="Uniform"  ToolTip="{DynamicResource ResourceKey=ResPortrait}" 
                                       Cursor="Hand" ShowMenu="False"></dxe:ImageEdit>

 

 

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;
                }
            }
        }
ImageEdit 加载图片

 

Save :

ImageEdit 加载图片
ImageEdit 加载图片
  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();
        }
ImageEdit 加载图片

 

ImageEdit 加载图片

 

Load:

 iePortrait.EditValue = this.Base64ToBitmapImage(selectedPortrait.Portrait);

 

ImageEdit 加载图片
  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;
        }
ImageEdit 加载图片

ImageEdit 加载图片

上一篇:博客新开,记录每一天的点点滴滴


下一篇:TCP与UDP的区别