Esempio n. 1
0
        private void Initialize(Bitmap bitmap, RtfImageFormat format, float dpiX, float dpiY)
        {
            _bitmap = bitmap;
            _format = format;

            SetDpi(dpiX, dpiY);
        }
Esempio n. 2
0
        private void Initialize(Bitmap bitmap, RtfImageFormat format)
        {
            float dpiX;
            float dpiY;

            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                dpiX = graphics.DpiX;
                dpiY = graphics.DpiY;
            }

            Initialize(bitmap, format, dpiX, dpiY);
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes an instance of ESCommon.Rtf.RtfImage class.
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        public RtfImage(Bitmap bitmap)
        {
            RtfImageFormat format = RtfImageFormat.Wmf;

            if (bitmap.RawFormat.Equals(ImageFormat.Jpeg))
            {
                format = RtfImageFormat.Jpeg;
            }
            else if (bitmap.RawFormat.Equals(ImageFormat.Png))
            {
                format = RtfImageFormat.Png;
            }

            Initialize(bitmap, format);
        }
Esempio n. 4
0
 /// <param name="dpiX">Horizontal resolution</param>
 /// <param name="dpiX">Vertical resolution</param>
 public RtfImage(Bitmap bitmap, RtfImageFormat format, float dpiX, float dpiY)
 {
     Initialize(bitmap, format, dpiX, dpiY);
 }
Esempio n. 5
0
 /// <param name="format">Image format</param>
 public RtfImage(Bitmap bitmap, RtfImageFormat format)
 {
     Initialize(bitmap, format);
 }
Esempio n. 6
0
        //
 



        // Write the none shape image with control "\nonshppict" so that 
        // we can support copy/paste image on Wordpad or legacy apps that only
        // handle windows metafile as the cotnrol "\wmetafileN" 
        private void WriteNoneShapeImage(DocumentNode documentNode, Stream imageStream, RtfImageFormat imageFormat) 
        {
            // Add the image(picture) control 
            _rtfBuilder.Append("{\\nonshppict{\\pict");

            // Add the image(picture) width control
            _rtfBuilder.Append("\\picwgoal"); 
            _rtfBuilder.Append(Converters.PxToTwipRounded(documentNode.FormatState.ImageWidth).ToString(CultureInfo.InvariantCulture));
 
            // Add the image(picture) height control 
            _rtfBuilder.Append("\\pichgoal");
            _rtfBuilder.Append(Converters.PxToTwipRounded(documentNode.FormatState.ImageHeight).ToString(CultureInfo.InvariantCulture)); 

            _rtfBuilder.Append("\\wmetafile8");

            // Add new line to put the image hexa data 
            _rtfBuilder.Append("\n");
 
            if (imageFormat != RtfImageFormat.Unknown) 
            {
                string metafileHexDataString = ConvertToMetafileHexDataString(imageStream); 

                _rtfBuilder.Append(metafileHexDataString);
            }
 
            // Add the curly bracket for closing image(picture) control
            _rtfBuilder.Append("}}"); 
        } 
Esempio n. 7
0
        // Write the shape image with control "\shppict" 
        private void WriteShapeImage(DocumentNode documentNode, Stream imageStream, RtfImageFormat imageFormat) 
        {
            // Add the image(picture) control 
            _rtfBuilder.Append("{\\*\\shppict{\\pict");

            // Get the current image input size
            Size imageInputSize = new Size(documentNode.FormatState.ImageWidth, documentNode.FormatState.ImageHeight); 

            // Get the natural size that is on the bitmap source 
            Size imageNaturalSize; 
            System.Windows.Media.Imaging.BitmapSource bitmapSource = (System.Windows.Media.Imaging.BitmapSource)System.Windows.Media.Imaging.BitmapFrame.Create(imageStream);
            if (bitmapSource != null) 
            {
                imageNaturalSize = new Size(bitmapSource.Width, bitmapSource.Height);
            }
            else 
            {
                imageNaturalSize = new Size(imageInputSize.Width, imageInputSize.Height); 
            } 

            // Get the stretch and stretch direction to apply the image scale factor 
            System.Windows.Media.Stretch imageStretch = GetImageStretch(documentNode.FormatState.ImageStretch);
            System.Windows.Controls.StretchDirection imageStretchDirection = GetImageStretchDirection(documentNode.FormatState.ImageStretchDirection);

            // Do a simple fixup to handle "0" input size, 
            // which in practice means unspecified.
            if (imageInputSize.Width == 0) 
            { 
                if (imageInputSize.Height == 0)
                { 
                    imageInputSize.Width = imageNaturalSize.Width;
                }
                else
                { 
                    //
                    imageInputSize.Width = imageNaturalSize.Width * (imageInputSize.Height / imageNaturalSize.Height); 
                } 
            }
            if (imageInputSize.Height == 0) 
            {
                if (imageInputSize.Width == 0)
                {
                    imageInputSize.Height = imageNaturalSize.Height; 
                }
                else 
                { 
                    //
                    imageInputSize.Height = imageNaturalSize.Height * (imageInputSize.Width / imageNaturalSize.Width); 
                }
            }

            // Get computed image scale factor 
            Size scaleFactor = System.Windows.Controls.Viewbox.ComputeScaleFactor(
                                   imageInputSize, 
                                   imageNaturalSize, 
                                   imageStretch,
                                   imageStretchDirection); 

            // Add the image(picture) width control
            _rtfBuilder.Append("\\picwgoal");
            _rtfBuilder.Append(Converters.PxToTwipRounded(imageNaturalSize.Width * scaleFactor.Width).ToString(CultureInfo.InvariantCulture)); 

            // Add the image(picture) height control 
            _rtfBuilder.Append("\\pichgoal"); 
            _rtfBuilder.Append(Converters.PxToTwipRounded(imageNaturalSize.Height * scaleFactor.Height).ToString(CultureInfo.InvariantCulture));
 
            // Add the image(picture)type control according to image type(name)
            switch (imageFormat)
            {
                case RtfImageFormat.Gif: 
                case RtfImageFormat.Tif:
                case RtfImageFormat.Bmp: 
                case RtfImageFormat.Dib: 
                case RtfImageFormat.Png:
                    _rtfBuilder.Append("\\pngblip"); 
                    break;

                case RtfImageFormat.Jpeg:
                    _rtfBuilder.Append("\\jpegblip"); 
                    break;
            } 
 
            // Add new line to put the image hexa data
            _rtfBuilder.Append("\r\n"); 

            if (imageFormat != RtfImageFormat.Unknown)
            {
                // Convert the image binary data to hex data string that is the default image 
                // data type on Rtf content
                string imageHexDataString = ConvertToImageHexDataString(imageStream); 
 
                // Add the image(picture) hex data
                _rtfBuilder.Append(imageHexDataString); 
            }

            // Add the curly bracket for closing image(picture) control
            _rtfBuilder.Append("}}"); 
        }