Beispiel #1
0
        //protected override void CopyCore()
        //{
        //    try
        //    {
        //        //var width = Source.Width;
        //        //var height = Source.Height;
        //        //var bmpCopied = new RenderTargetBitmap((int)Math.Round(width), (int)Math.Round(height), 96, 96,
        //        //    PixelFormats.Default);
        //        //var dv = new DrawingVisual();
        //        //using (var dc = dv.RenderOpen())
        //        //{
        //        //    var vb = new VisualBrush(dv);
        //        //    dc.DrawRectangle(vb, null, new Rect(new Point(), new Size(width, height)));
        //        //}
        //        //bmpCopied.Render(dv);
        //        //Clipboard.SetImage(bmpCopied);

        //        //var source = (BitmapSource)Source;
        //        //var visual = new DrawingVisual();
        //        //var context = visual.RenderOpen();
        //        //context.DrawImage(Source, new Rect(0.0, 0.0, source.Width, source.Height));
        //        //context.Close();
        //        ////var bitmap = new RenderTargetBitmap(source.PixelWidth, (int)source.PixelHeight, 96.0, 96.0, PixelFormats.Pbgra32);
        //        //var bitmap = new RenderTargetBitmap(source.PixelWidth, (int)source.PixelHeight, 96.0, 96.0, PixelFormats.Default);
        //        //bitmap.Render(visual);
        //        //Clipboard.SetImage(bitmap);

        //        //var img = new BitmapImage();
        //        //var stream = new MemoryStream((byte[]) EditValue);
        //        //{
        //        //    img.BeginInit();
        //        //    img.StreamSource = stream;
        //        //    img.EndInit();
        //        //}
        //        //Clipboard.SetImage(img);

        //        //Clipboard.SetImage(ImageLoader.GetSafeBitmapSource((BitmapSource) Source, ImageEffect));
        //    }
        //        // ReSharper disable once EmptyGeneralCatchClause
        //    catch { }
        //}

        private void OnImageLoading(ImageLoadingEventArgs e)
        {
            var handler = ImageLoading;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Beispiel #2
0
        private ImageSource LoadImage()
        {
            var dialog = new OpenFileDialog
            {
                Filter = EditorLocalizer.GetString(EditorStringId.ImageEdit_OpenFileFilter)
            };

            if (dialog.ShowDialog() == true)
            {
                var e = new ImageLoadingEventArgs(dialog.FileName);
                OnImageLoading(e);
                if (e.IsCanceled)
                {
                    return(null);
                }

                using (var stream = dialog.OpenFile())
                {
                    var data = new MemoryStream(stream.GetDataFromStream());
                    return(ImageHelper.CreateImageFromStream(data));
                }
            }
            return(null);
        }