Пример #1
0
        public static UserFile UploadUserFile(string fileName, FrameworkElement image, FrameworkElement focus, PropertyChangedEventHandler eventHandler)
        {
            FileCollection  _files = new FileCollection("1", 1024000);
            WriteableBitmap bmp    = new WriteableBitmap(image, null);

            System.IO.Stream dstStream = new System.IO.MemoryStream();
            JpegHelper.EncodeJpeg(bmp, dstStream);
            dstStream.Position = 0;//用于上传时从新读取

            MixObjectsSoapClient.Point point = new MixObjectsSoapClient.Point();
            point.X = (int)Double.Parse(focus.GetValue(Canvas.LeftProperty).ToString());
            point.Y = (int)Double.Parse(focus.GetValue(Canvas.TopProperty).ToString());

            MixObjectsSoapClient.Size size = new MixObjectsSoapClient.Size();
            size.Width  = (int)Double.Parse(focus.Width.ToString());
            size.Height = (int)Double.Parse(focus.Height.ToString());

            UserFile imageFile = new UserFile()
            {
                FileName = fileName, FileStream = dstStream, GrabPoint = point, GrabSize = size
            };                                                                                                                      // ofd.File;

            imageFile.PropertyChanged += eventHandler;
            _files.Add(imageFile);
            _files.UploadFiles();
            _files.RemoveAt(0);
            return(imageFile);
        }
        /// <summary>
        /// 保存到本地
        /// </summary>
        private void DownLoadAvatar_Click(object sender, RoutedEventArgs e)
        {
            if (saveFileDlg.ShowDialog().Value)
            {
                using (Stream dstStream = saveFileDlg.OpenFile())
                {
                    try
                    {
                        Image  image;
                        double Size = FocusWidth > FocusHeight ? FocusWidth : FocusHeight;//hack:将高宽转为size,这样就可以将ui元素中的内容保存到本地了

                        if (popMenu.Tag.ToString() == "LargeImageScrollViewer")
                        {
                            image = new Image()
                            {
                                Width = Size, Height = Size, Source = LargeImage.Source
                            }
                        }
                        ;
                        else if (popMenu.Tag.ToString() == "MediumImageScrollViewer")
                        {
                            image = new Image()
                            {
                                Width = Size * 0.8, Height = Size * 0.6, Source = MediumImage.Source
                            }
                        }
                        ;
                        else
                        {
                            image = new Image()
                            {
                                Width = Size * 0.8, Height = Size * 0.6, Source = SmallImage.Source
                            }
                        };

                        WriteableBitmap bmp = new WriteableBitmap(image, null);
                        JpegHelper.EncodeJpeg(bmp, dstStream);
                    }
                    catch (Exception ex)
                    {
                        Utils.ShowMessageBox("Error saving snapshot", ex.Message);
                    }
                }
            }
        }