public void ShowDialogInternal(Inline orgInline, Action<Inline, Inline> replaceCurrentImageCallback, string executeToolName, RadRichTextBox owner)
        {
            this.SetOwner(owner);
            this.originalInline = orgInline;
            if (orgInline is ImageInline)
            {
                this.originalImageInline = (ImageInline)orgInline;
            }
            else if (orgInline is FloatingImageBlock)
            {
                this.originalImageInline = ((FloatingImageBlock)orgInline).ImageInline;
            }
            else
            {
                throw new InvalidOperationException("Unable to find image element.");
            }

            RadBitmap image = new RadBitmap(this.originalImageInline.ImageSource);
            this.isRotated = false;
            this.originalAspect = new Size(this.originalImageInline.Width / image.Width, this.originalImageInline.Height / image.Height);
            this.originalRotateAngle = this.originalImageInline.RotateAngle;


            this.replaceCurrentImageCallback = replaceCurrentImageCallback;
            this.ImageEditorUI.Image = image;

            this.ShowDialog();
            this.StartExecuteTool(executeToolName);
        }
 public void Export(RadBitmap image, Stream stream)
 {
     Bitmap bitmap = image.ToBitmap();
     FreeImageBitmap freeImageBitmap = new FreeImageBitmap(bitmap);
  
     freeImageBitmap.Save(stream, this.GetImageFormat());
 }
        public void Export(RadBitmap image, Stream stream)
        {
            Bitmap          bitmap          = image.ToBitmap();
            FreeImageBitmap freeImageBitmap = new FreeImageBitmap(bitmap);

            freeImageBitmap.Save(stream, this.GetImageFormat());
        }
Пример #4
0
        public void ShowDialogInternal(Inline orgInline, Action <Inline, Inline> replaceCurrentImageCallback, string executeToolName, RadRichTextBox owner)
        {
            this.SetOwner(owner);
            this.originalInline = orgInline;
            if (orgInline is ImageInline)
            {
                this.originalImageInline = (ImageInline)orgInline;
            }
            else if (orgInline is FloatingImageBlock)
            {
                this.originalImageInline = ((FloatingImageBlock)orgInline).ImageInline;
            }
            else
            {
                throw new InvalidOperationException("Unable to find image element.");
            }

            RadBitmap image = new RadBitmap(this.originalImageInline.ImageSource);

            this.isRotated           = false;
            this.originalAspect      = new Size(this.originalImageInline.Width / image.Width, this.originalImageInline.Height / image.Height);
            this.originalRotateAngle = this.originalImageInline.RotateAngle;


            this.replaceCurrentImageCallback = replaceCurrentImageCallback;
            this.ImageEditorUI.Image         = image;

            this.ShowDialog();
            this.StartExecuteTool(executeToolName);
        }
Пример #5
0
 public WatermarkCommandContext(double opacity, double rotation, double scale, RadBitmap image)
 {
     this.Opacity  = opacity;
     this.Rotation = rotation;
     this.Scale    = scale;
     this.Image    = image;
 }
 public WatermarkCommandContext(double opacity, double rotation, double scale, RadBitmap image)
 {
     this.Opacity = opacity;
     this.Rotation = rotation;
     this.Scale = scale;
     this.Image = image;
 }
 public byte[] Export(RadBitmap image)
 {
     using (MemoryStream stream = new MemoryStream())
     {
         this.Export(image, stream);
         return stream.ToArray();
     }
 }
 public byte[] Export(RadBitmap image)
 {
     using (MemoryStream stream = new MemoryStream())
     {
         this.Export(image, stream);
         return(stream.ToArray());
     }
 }
Пример #9
0
        public WatermarkTool()
        {
            this.settings = new WatermarkToolSettings();

            this.settings.open.Click += new RoutedEventHandler(Open_Click);

            Uri imageUri = ImageExampleHelper.GetResourceUri("Images/telerik-logo.png");

            this.watermarkBitmap = new RadBitmap(Application.GetResourceStream(imageUri).Stream);

            this.watermarkImage         = new Image();
            this.watermarkImage.Source  = new BitmapImage(imageUri);
            this.watermarkImage.Stretch = Stretch.None;

            this.watermarkCommand     = new WatermarkCommand();
            this.imageRotateTransform = new RotateTransform();
            this.imageScaleTransform  = new ScaleTransform();
            this.imageEditorScale     = new ScaleTransform();

            TransformGroup transform = new TransformGroup();

            transform.Children.Add(this.imageRotateTransform);
            transform.Children.Add(this.imageScaleTransform);
            transform.Children.Add(this.imageEditorScale);
            this.watermarkImage.RenderTransform = transform;

            this.watermarkImage.RenderTransformOrigin = new Point(0.5, 0.5);
            this.watermarkImage.HorizontalAlignment   = HorizontalAlignment.Center;
            this.watermarkImage.VerticalAlignment     = VerticalAlignment.Center;

            this.settings.opacity.ValueChanged  += new EventHandler(settings_ValueChanged);
            this.settings.rotation.ValueChanged += new EventHandler(settings_ValueChanged);
            this.settings.scale.ValueChanged    += new EventHandler(settings_ValueChanged);

            Binding opacityBinding = new Binding("Value");

            opacityBinding.Source = this.settings.opacity;
            BindingOperations.SetBinding(this.watermarkImage, Image.OpacityProperty, opacityBinding);

            Binding rotationBinding = new Binding("Value");

            rotationBinding.Source = this.settings.rotation;
            BindingOperations.SetBinding(this.imageRotateTransform, RotateTransform.AngleProperty, rotationBinding);

            Binding scaleXBinding = new Binding("Value");

            scaleXBinding.Source = this.settings.scale;
            BindingOperations.SetBinding(this.imageScaleTransform, ScaleTransform.ScaleXProperty, scaleXBinding);

            Binding scaleYBinding = new Binding("Value");

            scaleYBinding.Source = this.settings.scale;
            BindingOperations.SetBinding(this.imageScaleTransform, ScaleTransform.ScaleYProperty, scaleYBinding);
        }
        private RadBitmapData DecodeInternal(MemoryStream stream)
        {
            BitmapImage bitmap = new BitmapImage();

            bitmap.BeginInit();
            bitmap.CreateOptions = BitmapCreateOptions.None;
            bitmap.StreamSource = stream;
            bitmap.EndInit();

            RadBitmap result = new RadBitmap(bitmap);

            return new RadBitmapData(result.Width, result.Height, result.GetPixels());
        }
        private RadBitmapData DecodeInternal(MemoryStream stream)
        {
            BitmapImage bitmap = new BitmapImage();

            bitmap.BeginInit();
            bitmap.CreateOptions = BitmapCreateOptions.None;
            bitmap.StreamSource  = stream;
            bitmap.EndInit();

            RadBitmap result = new RadBitmap(bitmap);

            return(new RadBitmapData(result.Width, result.Height, result.GetPixels()));
        }
Пример #12
0
 public void RestoreValue(object context, string savedValue)
 {
     BitmapImage image = context as BitmapImage;
     string[] stringBytes = savedValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
     byte[] bytes = new byte[stringBytes.Length];
     for (int i = 0; i < stringBytes.Length; i++)
     {
         bytes[i] = byte.Parse(stringBytes[i]);
     }
     MemoryStream stream = new MemoryStream(bytes);
     stream.Position = 0L;
     RadBitmap radBitmap = new RadBitmap(stream);
     image.SetSource(stream);
 }
Пример #13
0
        public static Bitmap ToBitmap(this RadBitmap radBitmap)
        {
            Bitmap bitmap = null;

            using (MemoryStream ms = new MemoryStream())
            {
                BitmapEncoder enc = new BmpBitmapEncoder();
                enc.Frames.Add(BitmapFrame.Create((BitmapSource)radBitmap.Bitmap));
                enc.Save(ms);
                bitmap = new Bitmap(ms);
            }

            return(bitmap);
        }
        public RadBitmapData Decode(Stream stream)
        {
            Metafile metaFile = new Metafile(stream);

            int   width       = metaFile.Width;
            int   height      = metaFile.Height;
            float scaleFactor = 1f;

            if (metaFile.Width > maxPixelSize ||
                metaFile.Height > maxPixelSize)
            {
                scaleFactor = Math.Max((float)metaFile.Width / (float)maxPixelSize, (float)metaFile.Height / (float)maxPixelSize);
                width       = (int)(width / scaleFactor);
                height      = (int)(height / scaleFactor);
            }

            // Create a PictureBox control and load the metafile
            PictureBox box = new PictureBox();

            box.Width     = width;
            box.Height    = height;
            box.BackColor = Color.White;
            box.SizeMode  = PictureBoxSizeMode.StretchImage;
            box.Image     = metaFile;

            // Create snapshot of the PictureBox and save it as a bitmap
            Bitmap bmp = new Bitmap(width, height);

            box.DrawToBitmap(bmp, new Rectangle(0, 0, width, height));

            //load the image in WPF
            RadBitmap     result = null;
            RadBitmapData data   = null;

            using (MemoryStream output = new MemoryStream())
            {
                BitmapImage image = new BitmapImage();

                image.BeginInit();
                bmp.Save(output, this.encoder, null);
                output.Seek(0, SeekOrigin.Begin);
                image.StreamSource = output;
                image.EndInit();

                result = new RadBitmap(image);
                data   = new RadBitmapData(result.Width, result.Height, result.GetPixels());
            }

            return(data);
        }
Пример #15
0
        public WatermarkTool()
        {
            this.settings = new WatermarkToolSettings();

            this.settings.open.Click += new RoutedEventHandler(Open_Click);

            Uri imageUri = ImageExampleHelper.GetResourceUri("Images/telerik-logo.png");
            this.watermarkBitmap = new RadBitmap(Application.GetResourceStream(imageUri).Stream);

            this.watermarkImage = new Image();
            this.watermarkImage.Source = new BitmapImage(imageUri);
            this.watermarkImage.Stretch = Stretch.None;

            this.watermarkCommand = new WatermarkCommand();
            this.imageRotateTransform = new RotateTransform();
            this.imageScaleTransform = new ScaleTransform();
            this.imageEditorScale = new ScaleTransform();

            TransformGroup transform = new TransformGroup();
            transform.Children.Add(this.imageRotateTransform);
            transform.Children.Add(this.imageScaleTransform);
            transform.Children.Add(this.imageEditorScale);
            this.watermarkImage.RenderTransform = transform;

            this.watermarkImage.RenderTransformOrigin = new Point(0.5, 0.5);
            this.watermarkImage.HorizontalAlignment = HorizontalAlignment.Center;
            this.watermarkImage.VerticalAlignment = VerticalAlignment.Center;

            this.settings.opacity.ValueChanged += new EventHandler(settings_ValueChanged);
            this.settings.rotation.ValueChanged += new EventHandler(settings_ValueChanged);
            this.settings.scale.ValueChanged += new EventHandler(settings_ValueChanged);

            Binding opacityBinding = new Binding("Value");
            opacityBinding.Source = this.settings.opacity;
            BindingOperations.SetBinding(this.watermarkImage, Image.OpacityProperty, opacityBinding);

            Binding rotationBinding = new Binding("Value");
            rotationBinding.Source = this.settings.rotation;
            BindingOperations.SetBinding(this.imageRotateTransform, RotateTransform.AngleProperty, rotationBinding);

            Binding scaleXBinding = new Binding("Value");
            scaleXBinding.Source = this.settings.scale;
            BindingOperations.SetBinding(this.imageScaleTransform, ScaleTransform.ScaleXProperty, scaleXBinding);

            Binding scaleYBinding = new Binding("Value");
            scaleYBinding.Source = this.settings.scale;
            BindingOperations.SetBinding(this.imageScaleTransform, ScaleTransform.ScaleYProperty, scaleYBinding);

        }
Пример #16
0
        private void Open_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter      = "PNG Images (*.png)|*.png|JPEG Images (*.jpg,*.jpeg)|*.jpg;*.jpeg|All images|*.png;*.jpg;*.jpeg";
            ofd.FilterIndex = 3;
            if (ofd.ShowDialog() == true)
            {
                Stream fileStream = ofd.OpenFile();
                using (fileStream)
                {
                    this.watermarkBitmap       = new RadBitmap(fileStream);
                    this.watermarkImage.Source = this.watermarkBitmap.Bitmap;
                }
            }
        }
        public RadBitmapData Decode(Stream stream)
        {
            Metafile metaFile = new Metafile(stream);

            int width = metaFile.Width;
            int height = metaFile.Height;
            float scaleFactor = 1f;

            if (metaFile.Width > maxPixelSize || 
                metaFile.Height > maxPixelSize)
            {
                scaleFactor = Math.Max((float)metaFile.Width / (float)maxPixelSize, (float)metaFile.Height / (float)maxPixelSize);
                width = (int)(width / scaleFactor);
                height = (int)(height / scaleFactor);
            }

            // Create a PictureBox control and load the metafile
            PictureBox box = new PictureBox();
            box.Width = width;
            box.Height = height;
            box.BackColor = Color.White;
            box.SizeMode = PictureBoxSizeMode.StretchImage;
            box.Image = metaFile;

            // Create snapshot of the PictureBox and save it as a bitmap
            Bitmap bmp = new Bitmap(width, height);
            box.DrawToBitmap(bmp, new Rectangle(0, 0, width, height));

            //load the image in WPF
            RadBitmap result = null;
            RadBitmapData data = null;
            using (MemoryStream output = new MemoryStream())
            {
                BitmapImage image = new BitmapImage();

                image.BeginInit();
                bmp.Save(output, this.encoder, null);
                output.Seek(0, SeekOrigin.Begin);
                image.StreamSource = output;
                image.EndInit();

                result = new RadBitmap(image);
                data = new RadBitmapData(result.Width, result.Height, result.GetPixels());
            }

            return data;
        }
Пример #18
0
        public void RestoreValue(object context, string savedValue)
        {
            BitmapImage image = context as BitmapImage;

            string[] stringBytes = savedValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            byte[]   bytes       = new byte[stringBytes.Length];
            for (int i = 0; i < stringBytes.Length; i++)
            {
                bytes[i] = byte.Parse(stringBytes[i]);
            }
            MemoryStream stream = new MemoryStream(bytes);

            stream.Position = 0L;
            RadBitmap radBitmap = new RadBitmap(stream);

            image.SetSource(stream);
        }
Пример #19
0
 public string ProvideValue(object context)
 {
     string resultValue = string.Empty;
     BitmapImage image = context as BitmapImage;
     RadBitmap radImage = new RadBitmap(image);
     PngBitmapEncoder encoder = new PngBitmapEncoder();
     Stream stream = new MemoryStream();
     encoder.Frames.Add(radImage.Bitmap);
     encoder.Save(stream);
     stream.Position = 0L;
     StringBuilder builder = new StringBuilder();
     int readByte = 0;
     while ((readByte = stream.ReadByte()) != -1)
     {
         builder.Append(readByte + ",");
     }
     resultValue = builder.ToString();
     return resultValue;
 }
Пример #20
0
        public string ProvideValue(object context)
        {
            string           resultValue = string.Empty;
            BitmapImage      image       = context as BitmapImage;
            RadBitmap        radImage    = new RadBitmap(image);
            PngBitmapEncoder encoder     = new PngBitmapEncoder();
            Stream           stream      = new MemoryStream();

            encoder.Frames.Add(radImage.Bitmap);
            encoder.Save(stream);
            stream.Position = 0L;
            StringBuilder builder  = new StringBuilder();
            int           readByte = 0;

            while ((readByte = stream.ReadByte()) != -1)
            {
                builder.Append(readByte + ",");
            }
            resultValue = builder.ToString();
            return(resultValue);
        }
Пример #21
0
        public RadBitmap Execute(RadBitmap source, object context)
        {
            WatermarkCommandContext myContext = (WatermarkCommandContext)context;

            Grid grid = new Grid();

            grid.Children.Add(new Image()
            {
                Source  = source.Bitmap,
                Stretch = Stretch.None
            });

            Image image = new Image()
            {
                Source  = myContext.Image.Bitmap,
                Stretch = Stretch.None,
                Opacity = myContext.Opacity,
            };

            ScaleTransform scaleTransform = new ScaleTransform();

            scaleTransform.ScaleX = myContext.Scale;
            scaleTransform.ScaleY = myContext.Scale;

            RotateTransform rotateTransform = new RotateTransform();

            rotateTransform.Angle = myContext.Rotation;

            TransformGroup transform = new TransformGroup();

            transform.Children.Add(rotateTransform);
            transform.Children.Add(scaleTransform);

            image.RenderTransform       = transform;
            image.RenderTransformOrigin = new Point(0.5, 0.5);

            grid.Children.Add(image);

            return(new RadBitmap(source.Width, source.Height, grid));
        }
Пример #22
0
        public RadBitmap Execute(RadBitmap source, object context)
        {
            WatermarkCommandContext myContext = (WatermarkCommandContext)context;

            Grid grid = new Grid();
            grid.Children.Add(new Image()
            {
                Source = source.Bitmap,
                Stretch = Stretch.None
            });

            Image image = new Image()
            {
                Source = myContext.Image.Bitmap,
                Stretch = Stretch.None,
                Opacity = myContext.Opacity,
            };

            ScaleTransform scaleTransform = new ScaleTransform();
            scaleTransform.ScaleX = myContext.Scale;
            scaleTransform.ScaleY = myContext.Scale;

            RotateTransform rotateTransform = new RotateTransform();
            rotateTransform.Angle = myContext.Rotation;

            TransformGroup transform = new TransformGroup();
            transform.Children.Add(rotateTransform);
            transform.Children.Add(scaleTransform);

            image.RenderTransform = transform;
            image.RenderTransformOrigin = new Point(0.5, 0.5);

            grid.Children.Add(image);

            return new RadBitmap(source.Width, source.Height, grid);
        }
Пример #23
0
        protected override void ExecuteOverride(object parameter)
        {
            this.Owner.CommitTool();
            RadBitmap image = this.Owner.Image;

            RadUpload    upload = new RadUpload();
            MemoryStream stream = new MemoryStream();

            PngFormatProvider png = new PngFormatProvider();

            png.Export(image, stream);
            stream.Seek(0, SeekOrigin.Begin);

            RadUploadSelectedFile file = new RadUploadSelectedFile(stream, "image" + image.GetHashCode() + ".png");

            upload.TargetFolder     = "UploadFolder";
            upload.UploadServiceUrl = "SampleUploadHandler.ashx";
            upload.CurrentSession.SelectedFiles.Add(file);

            upload.PrepareSelectedFilesForUpload();
            upload.UploadFinished += new RoutedEventHandler(upload_UploadFinished);

            upload.StartUpload();
        }
Пример #24
0
        private void Open_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "PNG Images (*.png)|*.png|JPEG Images (*.jpg,*.jpeg)|*.jpg;*.jpeg|All images|*.png;*.jpg;*.jpeg";
            ofd.FilterIndex = 3;
            if (ofd.ShowDialog() == true)
            {

#if SILVERLIGHT
                Stream fileStream = ofd.File.OpenRead();
#else
                Stream fileStream = ofd.OpenFile();
#endif
                // Open the selected file to read.
                using (fileStream)
                {
                    this.watermarkBitmap = new RadBitmap(fileStream);
                    this.watermarkImage.Source = this.watermarkBitmap.Bitmap;
                }
            }
        }
Пример #25
0
        /// <summary>
        /// Takes a UI element converts it to an image.
        /// </summary>
        /// <param name="uiElement">The uiElement to add to the manifest</param>
        /// <param name="customForceLayoutUpdate">A custom method to force the ui element's layout.</param>
        private ImageInline ConvertToImageInline(UIElement uiElement, Action customForceLayoutUpdate = null)
        {
            //To make sure the items controls render properly
            //add it to the BusyContent's StackPanel quickly

            //The BusyIndicator should be open when rendering manifests
            BusyContentStackPanel.Children.Add(uiElement);

            //Update the layout
            if (customForceLayoutUpdate != null)
                customForceLayoutUpdate();
            else
                BusyContentStackPanel.UpdateLayout();

            uiElement.Measure(new Size(double.MaxValue, double.MaxValue));

            ImageInline imageInline = null;

            //Try to create the image inline
            try
            {
                var writableBitmap = new WriteableBitmap((int)uiElement.DesiredSize.Width, (int)uiElement.DesiredSize.Height);
                writableBitmap.Render(uiElement, null);
                writableBitmap.Invalidate();

                var radImage = new RadBitmap(writableBitmap);

                var stream = new MemoryStream();
                var provider = new PngFormatProvider();
                provider.Export(radImage, stream);

                //Remove the uiElements from the stackpanel so the user does not see it
                BusyContentStackPanel.Children.Clear();

                return new ImageInline(stream);
            }
            catch
            {
                imageInline = new ImageInline();

                //Remove the uiElements from the stackpanel so the user does not see it
                BusyContentStackPanel.Children.Clear();
            }

            return imageInline;
        }