tags:

views:

77

answers:

0

Hi everyone. The issue we’re having is we have a wpf richtextbox, and we’re pasting images into it, but we want to be able to limit the physical data size, not the display size of the images being pasted in. In other words, if a user paste in an image that’s 2MB, we want to automatically shrink it down to a more manageable size. We have to have many users who share richtextbox data. So their text and images gets saved up to a cloud database so other users may download it. Please note that when an image gets pasted in, it’s a System.Windows.Controls.Image object.

Here is the code which i am trying to use .Thanks in advance

private void OnPaste(object sender, ExecutedRoutedEventArgs e)
    {
        if (Clipboard.ContainsText())
        {
            string s = Clipboard.GetText();
            richTextBox.Selection.Text = s;
        }
        else if (Clipboard.ContainsImage())
        {  
            var img = new System.Windows.Controls.Image();
            var imgSrc = Clipboard.GetImage();
            img.Source = new FormatConvertedBitmap(imgSrc, PixelFormats.Bgr32, null, 0);
            //img.Source = ConvertBitMapToBitMapImage(imgSrc);
            var buc = new BlockUIContainer(img);
             System.Windows.Controls.Image newImage = new System.Windows.Controls.Image();
            //clone the image from the image in the flowdocument
            //img.Source = bi;
            newImage.Source = img.Source;
           // newImage.Height = imgSrc.Height;
           // newImage.Width =imgSrc.Width;
            newImage.Height = 100;
            newImage.Width = 100;
            newImage.UpdateLayout();
             InlineUIContainer img_inline = new InlineUIContainer(newImage);
            richTextBox.Selection.Start.Paragraph.Inlines.Add(img_inline);




        }

        else
        {
            richTextBox.Paste();
        }

    }