Ejemplo n.º 1
0
        /// <summary>
        /// Adds image watermark into source file, saves resulted file to out file.
        /// </summary>
        /// <param name="sourceFile">Source slides file to proceed.</param>
        /// <param name="outFile">Output slides file.</param>
        /// <param name="options">Watermark options.</param>
        public void AddImageWatermark(
            string sourceFile,
            string outFile,
            ImageWatermarkOptionsModel options
            )
        {
            using (var presentation = new Presentation(sourceFile))
            {
                var size = presentation.SlideSize.Size;
                var img  = ResizeImage(
                    new Bitmap(options.ImageFile),
                    options.ZoomPercent / 100.0
                    ) as Image;

                if (options.IsGrayScaled)
                {
                    img = ToolStripRenderer.CreateDisabledImage(img);
                }

                var imgx = presentation.Images.AddImage(img);

                var height = imgx.Height;
                var width  = imgx.Width;

                var centerW = (size.Width - width) / 2;
                var centerH = (size.Height - height) / 2;

                foreach (var slide in presentation.Slides)
                {
                    IPictureFrame pf = slide.Shapes.AddPictureFrame(
                        ShapeType.Rectangle,
                        centerW, centerH,
                        imgx.Width, imgx.Height,
                        imgx
                        );

                    pf.Name = "WaterMark";

                    pf.LineFormat.FillFormat.FillType = FillType.NoFill;

                    pf.Rotation = options.RotationAngleDegrees;
                }

                presentation.Save(outFile, GetFormatFromSource(sourceFile));
            }
        }
Ejemplo n.º 2
0
        protected void ProcessImageWatermarkButton_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                if (CheckFileInputs(UploadImageInput))
                {
                    try
                    {
                        var files = UploadFiles(FolderNameHidden.Value, UploadImageInput);
                        if (files != null && files.Count == 1)
                        {
                            ImageWatermarkOptionsModel imageWatermarkOptionsModel = new ImageWatermarkOptionsModel();
                            imageWatermarkOptionsModel.id       = FolderNameHidden.Value;
                            imageWatermarkOptionsModel.FileName = files[0].FileName;

                            imageWatermarkOptionsModel.idMain       = FolderNameHidden.Value;
                            imageWatermarkOptionsModel.MainFileName = FileNameHidden.Value;

                            imageWatermarkOptionsModel.IsGrayScaled         = greyScale.Checked;
                            imageWatermarkOptionsModel.ZoomPercent          = int.Parse(zoom.Text);
                            imageWatermarkOptionsModel.RotationAngleDegrees = int.Parse(imageAngle.Text);


                            //var response = asposeSlides.AddImageWatermark(FileNameHidden.Value, FolderNameHidden.Value, files[0].FileName, files[0].FolderId, greyScale.Checked, double.Parse(zoom.Text), double.Parse(imageAngle.Text));
                            var response = asposeSlides.AddImageWatermark(imageWatermarkOptionsModel);
                            SuccessLabel.InnerText = Resources["WatermarkAddedSuccessMessage"];
                            PerformResponse(response, ImageMessage, ShowDownloadPage);
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowErrorMessage(ImageMessage, "Error: " + ex.Message);
                    }
                }
                else
                {
                    ShowErrorMessage(ImageMessage, Resources["FileSelectMessage"]);
                }
            }
        }