コード例 #1
0
        }         // DoInsertImage

        // ----------------------------------------------------------------------
        protected virtual void SaveImage(byte[] imageBuffer, RtfVisualImageFormat format, string fileName, Size size)
        {
            ImageFormat targetFormat = settings.ImageAdapter.TargetFormat;

            float scaleOffset    = settings.ScaleOffset;
            float scaleExtension = settings.ScaleExtension;

            using (System.Drawing.Image image = System.Drawing.Image.FromStream(
                       new MemoryStream(imageBuffer, 0, imageBuffer.Length)))
            {
                Bitmap   convertedImage = new Bitmap(new Bitmap(size.Width, size.Height, image.PixelFormat));
                Graphics graphic        = Graphics.FromImage(convertedImage);
                graphic.CompositingQuality = CompositingQuality.HighQuality;
                graphic.SmoothingMode      = SmoothingMode.HighQuality;
                graphic.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                RectangleF rectangle = new RectangleF(
                    scaleOffset,
                    scaleOffset,
                    size.Width + scaleExtension,
                    size.Height + scaleExtension);

                if (settings.BackgroundColor.HasValue)
                {
                    graphic.Clear(settings.BackgroundColor.Value);
                }

                graphic.DrawImage(image, rectangle);
                convertedImage.Save(fileName, targetFormat);
            }
        }         // SaveImage
コード例 #2
0
        }         // DoInsertImage

        // ----------------------------------------------------------------------
        protected virtual void SaveImage(byte[] imageBuffer, RtfVisualImageFormat format, string fileName, Size size)
        {
            ImageFormat targetFormat = settings.ImageAdapter.TargetFormat;

            float scaleOffset    = settings.ScaleOffset;
            float scaleExtension = settings.ScaleExtension;

            using (var memory = new MemoryStream(imageBuffer))
                using (var random = memory.AsRandomAccessStream())
                {
                    //var convertedImage = new BitmapImage();
                    //convertedImage.SetSource(random);

                    //Graphics graphic = Graphics.FromImage( convertedImage );
                    //graphic.CompositingQuality = CompositingQuality.HighQuality;
                    //graphic.SmoothingMode = SmoothingMode.HighQuality;
                    //graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    //RectangleF rectangle = new RectangleF(
                    //	scaleOffset,
                    //	scaleOffset,
                    //	size.Width + scaleExtension,
                    //	size.Height + scaleExtension );

                    //if ( settings.BackgroundColor.HasValue )
                    //{
                    //	graphic.Clear( settings.BackgroundColor.Value );
                    //}

                    //graphic.DrawImage( image, rectangle );
                    //convertedImage.Save( fileName, targetFormat );
                }
        }         // SaveImage
コード例 #3
0
        } // ResolveFileName

        public int CalcImageWidth(RtfVisualImageFormat format, int width,
                                  int desiredWidth, int scaleWidthPercent)
        {
            var imgScaleX = scaleWidthPercent / 100.0f;

            return((int)Math.Round((double)desiredWidth * imgScaleX / TwipsPerInch * DpiX));
        } // CalcImageWidth
コード例 #4
0
        } // CalcImageWidth

        public int CalcImageHeight(RtfVisualImageFormat format, int height,
                                   int desiredHeight, int scaleHeightPercent)
        {
            var imgScaleY = scaleHeightPercent / 100.0f;

            return((int)Math.Round((double)desiredHeight * imgScaleY / TwipsPerInch * DpiY));
        } // CalcImageHeight
コード例 #5
0
        }                           // DpiY

        public ImageFormat GetImageFormat(RtfVisualImageFormat rtfVisualImageFormat)
        {
            ImageFormat imageFormat = null;

            switch (rtfVisualImageFormat)
            {
            case RtfVisualImageFormat.Emf:
                imageFormat = ImageFormat.Emf;
                break;

            case RtfVisualImageFormat.Png:
                imageFormat = ImageFormat.Png;
                break;

            case RtfVisualImageFormat.Jpg:
                imageFormat = ImageFormat.Jpeg;
                break;

            case RtfVisualImageFormat.Wmf:
                imageFormat = ImageFormat.Wmf;
                break;

            case RtfVisualImageFormat.Bmp:
                imageFormat = ImageFormat.Bmp;
                break;
            }

            return(imageFormat);
        } // GetImageFormat
コード例 #6
0
ファイル: RtfTextConverter.cs プロジェクト: CloudIDEaaS/hydra
        }         // DoInsertBreak

        // ----------------------------------------------------------------------
        protected override void DoInsertImage(IRtfInterpreterContext context,
                                              RtfVisualImageFormat format,
                                              int width, int height, int desiredWidth, int desiredHeight,
                                              int scaleWidthPercent, int scaleHeightPercent,
                                              string imageDataHex
                                              )
        {
            string imageFormatText = settings.ImageFormatText;

            if (string.IsNullOrEmpty(imageFormatText))
            {
                return;
            }

            string imageText = string.Format(
                CultureInfo.InvariantCulture,
                imageFormatText,
                format,
                width,
                height,
                desiredWidth,
                desiredHeight,
                scaleWidthPercent,
                scaleHeightPercent,
                imageDataHex);

            plainText.Append(imageText);
        }         // DoInsertImage
コード例 #7
0
        }         // DoInsertBreak

        // ----------------------------------------------------------------------
        protected virtual void DoInsertImage(IRtfInterpreterContext context,
                                             RtfVisualImageFormat format,
                                             int width, int height, int desiredWidth, int desiredHeight,
                                             int scaleWidthPercent, int scaleHeightPercent,
                                             string imageDataHex
                                             )
        {
        }         // DoInsertImage
コード例 #8
0
 // ----------------------------------------------------------------------
 public RtfVisualImage(
     RtfVisualImageFormat format,
     RtfTextAlignment alignment,
     int width,
     int height,
     int desiredWidth,
     int desiredHeight,
     int scaleWidthPercent,
     int scaleHeightPercent,
     string imageDataHex,
     String importFileName
     ) :
     base(RtfVisualKind.Image)
 {
     if (width <= 0)
     {
         throw new ArgumentException(Strings.InvalidImageWidth(width));
     }
     if (height <= 0)
     {
         throw new ArgumentException(Strings.InvalidImageHeight(height));
     }
     if (desiredWidth <= 0)
     {
         throw new ArgumentException(Strings.InvalidImageDesiredWidth(desiredWidth));
     }
     if (desiredHeight <= 0)
     {
         throw new ArgumentException(Strings.InvalidImageDesiredHeight(desiredHeight));
     }
     if (scaleWidthPercent <= 0)
     {
         throw new ArgumentException(Strings.InvalidImageScaleWidth(scaleWidthPercent));
     }
     if (scaleHeightPercent <= 0)
     {
         throw new ArgumentException(Strings.InvalidImageScaleHeight(scaleHeightPercent));
     }
     if (imageDataHex == null)
     {
         throw new ArgumentNullException("imageDataHex");
     }
     if (importFileName == null)
     {
         throw new ArgumentNullException("importFileName");
     }
     this.format             = format;
     this.alignment          = alignment;
     this.width              = width;
     this.height             = height;
     this.desiredWidth       = desiredWidth;
     this.desiredHeight      = desiredHeight;
     this.scaleWidthPercent  = scaleWidthPercent;
     this.scaleHeightPercent = scaleHeightPercent;
     this.imageDataHex       = imageDataHex;
     this.importFileName     = importFileName;
 }         // RtfVisualImage
コード例 #9
0
		} // ScaleExtension

		// ----------------------------------------------------------------------
		public string GetImageFileName( int index, RtfVisualImageFormat rtfVisualImageFormat )
		{
			string imageFileName = this.imageAdapter.ResolveFileName( index, rtfVisualImageFormat );
			if ( !string.IsNullOrEmpty( this.imagesPath ) )
			{
				imageFileName = Path.Combine( imagesPath, imageFileName );
			}
			return imageFileName;
		} // GetImageFileName
コード例 #10
0
        // ----------------------------------------------------------------------
        public string GetImageFileName(int index, RtfVisualImageFormat rtfVisualImageFormat)
        {
            string imageFileName = imageAdapter.ResolveFileName(index, rtfVisualImageFormat);

            if (!string.IsNullOrEmpty(imagesPath))
            {
                imageFileName = Path.Combine(imagesPath, imageFileName);
            }
            return(imageFileName);
        }         // GetImageFileName
コード例 #11
0
        } // GetImageFormat

        public string ResolveFileName(int index, RtfVisualImageFormat rtfVisualImageFormat)
        {
            var imageFormat = TargetFormat ?? GetImageFormat(rtfVisualImageFormat);

            return(string.Format(
                       CultureInfo.InvariantCulture,
                       FileNamePattern,
                       index,
                       GetFileImageExtension(imageFormat)));
        } // ResolveFileName
        // ----------------------------------------------------------------------
        public void InsertImage( IRtfInterpreterContext context, RtfVisualImageFormat format,
			int width, int height, int desiredWidth, int desiredHeight,
			int scaleWidthPercent, int scaleHeightPercent, string imageDataHex
		)
        {
            if ( context != null )
            {
                DoInsertImage( context, format,
                    width, height, desiredWidth, desiredHeight,
                    scaleWidthPercent, scaleHeightPercent, imageDataHex );
            }
        }
コード例 #13
0
        }         // InsertBreak

        // ----------------------------------------------------------------------
        public void InsertImage(IRtfInterpreterContext context, RtfVisualImageFormat format,
                                int width, int height, int desiredWidth, int desiredHeight,
                                int scaleWidthPercent, int scaleHeightPercent, string imageDataHex
                                )
        {
            if (context != null)
            {
                DoInsertImage(context, format,
                              width, height, desiredWidth, desiredHeight,
                              scaleWidthPercent, scaleHeightPercent, imageDataHex);
            }
        }         // InsertImage
コード例 #14
0
        }         // DoBeginDocument

        // ----------------------------------------------------------------------
        protected override void DoInsertImage(IRtfInterpreterContext context,
                                              RtfVisualImageFormat format,
                                              int width, int height,
                                              int desiredWidth, int desiredHeight,
                                              int scaleWidthPercent, int scaleHeightPercent,
                                              string imageDataHex, String importFileName
                                              )
        {
            int    imageIndex = convertedImages.Count + 1;
            string fileName   = settings.GetImageFileName(imageIndex, format);

            EnsureImagesPath(fileName);

            byte[]      imageBuffer = RtfVisualImage.ToBinary(imageDataHex);
            Size        imageSize;
            ImageFormat imageFormat;

            if (settings.ImageAdapter.TargetFormat == null)
            {
                using (var memory = new MemoryStream(imageBuffer))
                    using (var random = memory.AsRandomAccessStream())
                    {
                        var image = new BitmapImage();
                        image.SetSource(random);

                        imageFormat = ImageFormat.Jpeg;
                        imageSize   = new Size(image.PixelWidth, image.PixelHeight);
                    }
                using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(fileName, FileMode.Create)))
                {
                    binaryWriter.Write(imageBuffer);
                }
            }
            else
            {
                imageFormat = settings.ImageAdapter.TargetFormat;
                if (settings.ScaleImage)
                {
                    imageSize = new Size(
                        settings.ImageAdapter.CalcImageWidth(format, width, desiredWidth, scaleWidthPercent),
                        settings.ImageAdapter.CalcImageHeight(format, height, desiredHeight, scaleHeightPercent));
                }
                else
                {
                    imageSize = new Size(width, height);
                }

                SaveImage(imageBuffer, format, fileName, imageSize);
            }

            convertedImages.Add(new RtfConvertedImageInfo(fileName, imageFormat, imageSize));
        }         // DoInsertImage
コード例 #15
0
        }         // DoInsertBreak

        // ----------------------------------------------------------------------
        protected override void DoInsertImage(IRtfInterpreterContext context,
                                              RtfVisualImageFormat format,
                                              int width, int height, int desiredWidth, int desiredHeight,
                                              int scaleWidthPercent, int scaleHeightPercent,
                                              string imageDataHex, string importFileName
                                              )
        {
            FlushPendingText();
            AppendAlignedVisual(new RtfVisualImage(format,
                                                   context.GetSafeCurrentTextFormat().Alignment,
                                                   width, height, desiredWidth, desiredHeight,
                                                   scaleWidthPercent, scaleHeightPercent, imageDataHex, importFileName));
        }         // DoInsertImage
コード例 #16
0
		} // DoInsertBreak

		// ----------------------------------------------------------------------
		protected override void DoInsertImage( IRtfInterpreterContext context,
			RtfVisualImageFormat format,
			int width, int height, int desiredWidth, int desiredHeight,
			int scaleWidthPercent, int scaleHeightPercent,
			string imageDataHex
		)
		{
			FlushPendingText();
			this.visualContent.Add( new RtfVisualImage( format,
				context.GetSafeCurrentTextFormat().Alignment,
				width, height, desiredWidth, desiredHeight,
				scaleWidthPercent, scaleHeightPercent, imageDataHex ) );
		} // DoInsertImage
コード例 #17
0
        private byte[] _imageDataBinary; // cached info only

        public RtfVisualImage(
            RtfVisualImageFormat format,
            RtfTextAlignment alignment,
            int width,
            int height,
            int desiredWidth,
            int desiredHeight,
            int scaleWidthPercent,
            int scaleHeightPercent,
            string imageDataHex
            ) :
            base(RtfVisualKind.Image)
        {
            if (width <= 0)
            {
                throw new ArgumentException(Strings.InvalidImageWidth(width));
            }
            if (height <= 0)
            {
                throw new ArgumentException(Strings.InvalidImageHeight(height));
            }
            if (desiredWidth <= 0)
            {
                throw new ArgumentException(Strings.InvalidImageDesiredWidth(desiredWidth));
            }
            if (desiredHeight <= 0)
            {
                throw new ArgumentException(Strings.InvalidImageDesiredHeight(desiredHeight));
            }
            if (scaleWidthPercent <= 0)
            {
                throw new ArgumentException(Strings.InvalidImageScaleWidth(scaleWidthPercent));
            }
            if (scaleHeightPercent <= 0)
            {
                throw new ArgumentException(Strings.InvalidImageScaleHeight(scaleHeightPercent));
            }
            if (imageDataHex == null)
            {
                throw new ArgumentNullException(nameof(imageDataHex));
            }
            Format             = format;
            Alignment          = alignment;
            Width              = width;
            Height             = height;
            DesiredWidth       = desiredWidth;
            DesiredHeight      = desiredHeight;
            ScaleWidthPercent  = scaleWidthPercent;
            ScaleHeightPercent = scaleHeightPercent;
            ImageDataHex       = imageDataHex;
        } // RtfVisualImage
コード例 #18
0
        private byte[] imageDataBinary; // cached info only

        #endregion Fields

        #region Constructors

        // ----------------------------------------------------------------------
        public RtfVisualImage(
			RtfVisualImageFormat format,
			RtfTextAlignment alignment,
			int width,
			int height,
			int desiredWidth,
			int desiredHeight,
			int scaleWidthPercent,
			int scaleHeightPercent,
			string imageDataHex
		)
            : base(RtfVisualKind.Image)
        {
            if ( width <= 0 )
            {
                throw new ArgumentException( Strings.InvalidImageWidth( width ) );
            }
            if ( height <= 0 )
            {
                throw new ArgumentException( Strings.InvalidImageHeight( height ) );
            }
            if ( desiredWidth <= 0 )
            {
                throw new ArgumentException( Strings.InvalidImageDesiredWidth( desiredWidth ) );
            }
            if ( desiredHeight <= 0 )
            {
                throw new ArgumentException( Strings.InvalidImageDesiredHeight( desiredHeight ) );
            }
            if ( scaleWidthPercent <= 0 )
            {
                throw new ArgumentException( Strings.InvalidImageScaleWidth( scaleWidthPercent ) );
            }
            if ( scaleHeightPercent <= 0 )
            {
                throw new ArgumentException( Strings.InvalidImageScaleHeight( scaleHeightPercent ) );
            }
            if ( imageDataHex == null )
            {
                throw new ArgumentNullException( "imageDataHex" );
            }
            this.format = format;
            this.alignment = alignment;
            this.width = width;
            this.height = height;
            this.desiredWidth = desiredWidth;
            this.desiredHeight = desiredHeight;
            this.scaleWidthPercent = scaleWidthPercent;
            this.scaleHeightPercent = scaleHeightPercent;
            this.imageDataHex = imageDataHex;
        }
コード例 #19
0
        // ----------------------------------------------------------------------
        public string GetImageFileName(int index, RtfVisualImageFormat rtfVisualImageFormat)
        {
            string imageFileName = imageAdapter.ResolveFileName(index, rtfVisualImageFormat);

            if (!string.IsNullOrEmpty(imagesPath))
            {
#if FILEIO
                imageFileName = Path.Combine(imagesPath, imageFileName);
#else
                imageFileName = imagesPath.TrimEnd('\\') + "\\" + imageFileName.TrimStart('\\');
#endif
            }
            return(imageFileName);
        } // GetImageFileName
コード例 #20
0
        }         // GetImageFormat

        // ----------------------------------------------------------------------
        public string ResolveFileName(int index, RtfVisualImageFormat rtfVisualImageFormat)
        {
            ImageFormat imageFormat = this.targetFormat;

            if (imageFormat == null)
            {
                imageFormat = GetImageFormat(rtfVisualImageFormat);
            }

            return(string.Format(
                       CultureInfo.InvariantCulture,
                       this.fileNamePattern,
                       index,
                       GetFileImageExtension(imageFormat)));
        }         // ResolveFileName
コード例 #21
0
        }         // DoBeginDocument

        // ----------------------------------------------------------------------
        protected override void DoInsertImage(IRtfInterpreterContext context,
                                              RtfVisualImageFormat format,
                                              int width, int height,
                                              int desiredWidth, int desiredHeight,
                                              int scaleWidthPercent, int scaleHeightPercent,
                                              string imageDataHex
                                              )
        {
            int    imageIndex = convertedImages.Count + 1;
            string fileName   = settings.GetImageFileName(imageIndex, format);

            EnsureImagesPath(fileName);

            byte[]      imageBuffer = RtfVisualImage.ToBinary(imageDataHex);
            Size        imageSize;
            ImageFormat imageFormat;

            if (settings.ImageAdapter.TargetFormat == null)
            {
                using (System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(imageBuffer)))
                {
                    imageFormat = image.RawFormat;
                    imageSize   = image.Size;
                }
                using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(fileName, FileMode.Create)))
                {
                    binaryWriter.Write(imageBuffer);
                }
            }
            else
            {
                imageFormat = settings.ImageAdapter.TargetFormat;
                if (settings.ScaleImage)
                {
                    imageSize = new Size(
                        settings.ImageAdapter.CalcImageWidth(format, width, desiredWidth, scaleWidthPercent),
                        settings.ImageAdapter.CalcImageHeight(format, height, desiredHeight, scaleHeightPercent));
                }
                else
                {
                    imageSize = new Size(width, height);
                }

                SaveImage(imageBuffer, format, fileName, imageSize);
            }

            convertedImages.Add(new RtfConvertedImageInfo(fileName, imageFormat, imageSize));
        }         // DoInsertImage
コード例 #22
0
ファイル: RtfImageConverter.cs プロジェクト: haimon74/KanNaim
		} // DoBeginDocument

		// ----------------------------------------------------------------------
		protected override void DoInsertImage( IRtfInterpreterContext context,
			RtfVisualImageFormat format,
			int width, int height, 
			int desiredWidth, int desiredHeight,
			int scaleWidthPercent, int scaleHeightPercent,
			string imageDataHex
		)
		{
			int imageIndex = this.convertedImages.Count + 1;
			string fileName = this.settings.GetImageFileName( imageIndex, format );
			EnsureImagesPath( fileName );

			byte[] imageBuffer = RtfVisualImage.ToBinary( imageDataHex );
			Size imageSize;
			ImageFormat imageFormat;
			if ( this.settings.ImageAdapter.TargetFormat == null )
			{
				using ( System.Drawing.Image image = System.Drawing.Image.FromStream( new MemoryStream( imageBuffer ) ) )
				{
					imageFormat = image.RawFormat;
					imageSize = image.Size;
				}
				using ( BinaryWriter binaryWriter = new BinaryWriter( File.Open( fileName, FileMode.Create ) ) )
				{
					binaryWriter.Write( imageBuffer );
				}
			}
			else
			{
				imageFormat = this.settings.ImageAdapter.TargetFormat;
				if ( this.settings.ScaleImage )
				{
					imageSize = new Size(
					 this.settings.ImageAdapter.CalcImageWidth( format, width, desiredWidth, scaleWidthPercent ),
					 this.settings.ImageAdapter.CalcImageHeight( format, height, desiredHeight, scaleHeightPercent ) );
				}
				else
				{
					imageSize = new Size( width, height );
				}

				SaveImage( imageBuffer, format, fileName, imageSize );
			}

			this.convertedImages.Add( new RtfConvertedImageInfo( fileName, imageFormat, imageSize ) );
		} // DoInsertImage
コード例 #23
0
        }         // GetImageFormat
#endif

        // ----------------------------------------------------------------------
        public string ResolveFileName(int index, RtfVisualImageFormat rtfVisualImageFormat)
        {
#if DRAWING
            ImageFormat imageFormat = targetFormat ?? GetImageFormat(rtfVisualImageFormat);

            return(string.Format(
                       CultureInfo.InvariantCulture,
                       fileNamePattern,
                       index,
                       GetFileImageExtension(imageFormat)));
#else
            return(string.Format(
                       CultureInfo.InvariantCulture,
                       fileNamePattern,
                       index,
                       rtfVisualImageFormat));
#endif
        } // ResolveFileName
コード例 #24
0
        }         // NotifyInsertBreak

        // ----------------------------------------------------------------------
        protected void NotifyInsertImage(RtfVisualImageFormat format,
                                         int width, int height, int desiredWidth, int desiredHeight,
                                         int scaleWidthPercent, int scaleHeightPercent, string imageDataHex
                                         )
        {
            if (listeners != null)
            {
                foreach (IRtfInterpreterListener listener in listeners)
                {
                    listener.InsertImage(
                        context,
                        format,
                        width,
                        height,
                        desiredWidth,
                        desiredHeight,
                        scaleWidthPercent,
                        scaleHeightPercent,
                        imageDataHex);
                }
            }
        }         // NotifyInsertImage
コード例 #25
0
        }         // DoInsertBreak

        // ----------------------------------------------------------------------
        protected override void DoInsertImage(IRtfInterpreterContext context,
                                              RtfVisualImageFormat format,
                                              int width, int height, int desiredWidth, int desiredHeight,
                                              int scaleWidthPercent, int scaleHeightPercent,
                                              string imageDataHex
                                              )
        {
            if (settings.Enabled && !string.IsNullOrEmpty(settings.ImageFormatText))
            {
                WriteLine(string.Format(
                              CultureInfo.InvariantCulture,
                              settings.ImageFormatText,
                              format,
                              width,
                              height,
                              desiredWidth,
                              desiredHeight,
                              scaleWidthPercent,
                              scaleHeightPercent,
                              imageDataHex,
                              (imageDataHex.Length / 2)));
            }
        }         // DoInsertImage
コード例 #26
0
        // ----------------------------------------------------------------------
        protected void NotifyInsertImage( RtfVisualImageFormat format,
			int width, int height, int desiredWidth, int desiredHeight,
			int scaleWidthPercent, int scaleHeightPercent, string imageDataHex
		)
        {
            if ( listeners != null )
            {
                foreach ( IRtfInterpreterListener listener in listeners )
                {
                    listener.InsertImage(
                        context,
                        format,
                        width,
                        height,
                        desiredWidth,
                        desiredHeight,
                        scaleWidthPercent,
                        scaleHeightPercent,
                        imageDataHex );
                }
            }
        }
コード例 #27
0
 // ----------------------------------------------------------------------
 public int CalcImageHeight( RtfVisualImageFormat format, int height,
     int desiredHeight, int scaleHeightPercent)
 {
     float imgScaleY = scaleHeightPercent / 100.0f;
     return (int)Math.Round( (double)desiredHeight * imgScaleY / twipsPerInch * dpiY );
 }
コード例 #28
0
 // ----------------------------------------------------------------------
 public int CalcImageWidth( RtfVisualImageFormat format, int width,
     int desiredWidth, int scaleWidthPercent)
 {
     float imgScaleX = scaleWidthPercent / 100.0f;
     return (int)Math.Round( (double)desiredWidth * imgScaleX / twipsPerInch * dpiX );
 }
コード例 #29
0
ファイル: RtfImageConverter.cs プロジェクト: haimon74/KanNaim
		} // DoInsertImage

		// ----------------------------------------------------------------------
		protected virtual void SaveImage( byte[] imageBuffer, RtfVisualImageFormat format, string fileName, Size size )
		{
			ImageFormat targetFormat = this.settings.ImageAdapter.TargetFormat;

			float scaleOffset = this.settings.ScaleOffset;
			float scaleExtension = this.settings.ScaleExtension;
			using ( System.Drawing.Image image = System.Drawing.Image.FromStream(
				new MemoryStream( imageBuffer, 0, imageBuffer.Length ) ) )
			{
				Bitmap convertedImage = new Bitmap( new Bitmap( size.Width, size.Height, image.PixelFormat ) );
				Graphics graphic = Graphics.FromImage( convertedImage );
				graphic.CompositingQuality = CompositingQuality.HighQuality;
				graphic.SmoothingMode = SmoothingMode.HighQuality;
				graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
				RectangleF rectangle = new RectangleF( 
					scaleOffset, 
					scaleOffset, 
					size.Width + scaleExtension, 
					size.Height + scaleExtension );

				if ( this.settings.BackgroundColor.HasValue )
				{
					graphic.Clear( this.settings.BackgroundColor.Value );
				}

				graphic.DrawImage( image, rectangle );
				convertedImage.Save( fileName, targetFormat );
			}
		} // SaveImage
 // ----------------------------------------------------------------------
 protected override void DoVisitTag( IRtfTag tag )
 {
     switch ( tag.Name )
     {
         case RtfSpec.TagPictureFormatWinDib:
         case RtfSpec.TagPictureFormatWinBmp:
             format = RtfVisualImageFormat.Bmp;
             break;
         case RtfSpec.TagPictureFormatEmf:
             format = RtfVisualImageFormat.Emf;
             break;
         case RtfSpec.TagPictureFormatJpg:
             format = RtfVisualImageFormat.Jpg;
             break;
         case RtfSpec.TagPictureFormatPng:
             format = RtfVisualImageFormat.Png;
             break;
         case RtfSpec.TagPictureFormatWmf:
             format = RtfVisualImageFormat.Wmf;
             break;
         case RtfSpec.TagPictureWidth:
             width = tag.ValueAsNumber;
             desiredWidth = width;
             break;
         case RtfSpec.TagPictureHeight:
             height = tag.ValueAsNumber;
             desiredHeight = height;
             break;
         case RtfSpec.TagPictureWidthGoal:
             desiredWidth = tag.ValueAsNumber;
             if ( width == 0 )
             {
                 // hack to prevent WordPad documents which lack the \picw and \pich tags
                 // from resulting in an exception due to undefined width/height
                 width = desiredWidth;
             }
             break;
         case RtfSpec.TagPictureHeightGoal:
             desiredHeight = tag.ValueAsNumber;
             if ( height == 0 )
             {
                 // hack to prevent WordPad documents which lack the \picw and \pich tags
                 // from resulting in an exception due to undefined width/height
                 height = desiredHeight;
             }
             break;
         case RtfSpec.TagPictureWidthScale:
             scaleWidthPercent = tag.ValueAsNumber;
             break;
         case RtfSpec.TagPictureHeightScale:
             scaleHeightPercent = tag.ValueAsNumber;
             break;
     }
 }
        // ----------------------------------------------------------------------
        protected override void DoInsertImage( IRtfInterpreterContext context,
			RtfVisualImageFormat format,
			int width, int height, int desiredWidth, int desiredHeight,
			int scaleWidthPercent, int scaleHeightPercent,
			string imageDataHex
		)
        {
            if ( settings.Enabled && !string.IsNullOrEmpty( settings.ImageFormatText ) )
            {
                WriteLine( string.Format(
                    CultureInfo.InvariantCulture,
                    settings.ImageFormatText,
                    format,
                    width,
                    height,
                    desiredWidth,
                    desiredHeight,
                    scaleWidthPercent,
                    scaleHeightPercent,
                    imageDataHex,
                    (imageDataHex.Length / 2) ) );
            }
        }
コード例 #32
0
        // ----------------------------------------------------------------------
        public ImageFormat GetImageFormat( RtfVisualImageFormat rtfVisualImageFormat )
        {
            ImageFormat imageFormat = null;

            switch ( rtfVisualImageFormat )
            {
                case RtfVisualImageFormat.Emf:
                    imageFormat = ImageFormat.Emf;
                    break;
                case RtfVisualImageFormat.Png:
                    imageFormat = ImageFormat.Png;
                    break;
                case RtfVisualImageFormat.Jpg:
                    imageFormat = ImageFormat.Jpeg;
                    break;
                case RtfVisualImageFormat.Wmf:
                    imageFormat = ImageFormat.Wmf;
                    break;
                case RtfVisualImageFormat.Bmp:
                    imageFormat = ImageFormat.Bmp;
                    break;
            }

            return imageFormat;
        }
コード例 #33
0
        } // RtfHtmlConvertSettings

        public string GetImageUrl(int index, RtfVisualImageFormat rtfVisualImageFormat)
        {
            var imageFileName = ImageAdapter.ResolveFileName(index, rtfVisualImageFormat);

            return(imageFileName.Replace('\\', '/'));
        } // GetImageUrl
コード例 #34
0
        // ----------------------------------------------------------------------
        public string ResolveFileName( int index, RtfVisualImageFormat rtfVisualImageFormat )
        {
            ImageFormat imageFormat = targetFormat ?? GetImageFormat( rtfVisualImageFormat );

            return string.Format(
                CultureInfo.InvariantCulture,
                fileNamePattern,
                index,
                GetFileImageExtension( imageFormat ) );
        }
コード例 #35
0
		} // GetImageFormat

		// ----------------------------------------------------------------------
		public string ResolveFileName( int index, RtfVisualImageFormat rtfVisualImageFormat )
		{
			ImageFormat imageFormat = this.targetFormat;
			if ( imageFormat == null )
			{
				imageFormat = GetImageFormat( rtfVisualImageFormat );
			}

			return string.Format(
				CultureInfo.InvariantCulture,
				this.fileNamePattern,
				index,
				GetFileImageExtension( imageFormat ) );
		} // ResolveFileName
        // ----------------------------------------------------------------------
        protected virtual void DoInsertImage( IRtfInterpreterContext context,
			RtfVisualImageFormat format,
			int width, int height, int desiredWidth, int desiredHeight,
			int scaleWidthPercent, int scaleHeightPercent,
			string imageDataHex
		)
        {
        }
 // ----------------------------------------------------------------------
 public string GetImageUrl( int index, RtfVisualImageFormat rtfVisualImageFormat )
 {
     string imageFileName = imageAdapter.ResolveFileName( index, rtfVisualImageFormat );
     return imageFileName.Replace( '\\', '/' );
 }
 // ----------------------------------------------------------------------
 public void Reset()
 {
     format = RtfVisualImageFormat.Bmp;
     width = 0;
     height = 0;
     desiredWidth = 0;
     desiredHeight = 0;
     scaleWidthPercent = 100;
     scaleHeightPercent = 100;
     imageDataHex = null;
 }
コード例 #39
0
        // ----------------------------------------------------------------------
        protected override void DoInsertImage( IRtfInterpreterContext context,
            RtfVisualImageFormat format,
            int width, int height, int desiredWidth, int desiredHeight,
            int scaleWidthPercent, int scaleHeightPercent,
            string imageDataHex
            )
        {
            string imageFormatText = settings.ImageFormatText;
            if ( string.IsNullOrEmpty( imageFormatText ) )
            {
                return;
            }

            string imageText = string.Format(
                CultureInfo.InvariantCulture,
                imageFormatText,
                format,
                width,
                height,
                desiredWidth,
                desiredHeight,
                scaleWidthPercent,
                scaleHeightPercent,
                imageDataHex );

            plainText.Append( imageText );
        }