コード例 #1
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
コード例 #2
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