예제 #1
0
        private static void AddWatermark(IEnumerable <string> images, string instituce)
        {
            var assembly = Assembly.GetExecutingAssembly();
            var watermarkStreamResource = assembly.GetManifestResourceStream("Daliboris.Texty.Export.Watermarks." + instituce);

            if (watermarkStreamResource == null)
            {
                throw new Exception(string.Format("Watermark Daliboris.Texty.Export.Watermarks.{0} not found", instituce));
            }
            var imageWatermark = Image.FromStream(watermarkStreamResource);
            var watermark      = new ImageWatermark(imageWatermark);

            watermark.ContentAlignment = ContentAlignment.BottomCenter;
            watermark.Alpha            = 99F;

            foreach (var image in images)
            {
                var fi = new FileInfo(image);

                var tempFile = fi.FullName.Substring(0, fi.FullName.Length - fi.Extension.Length) + ".help" + fi.Extension;

                File.Move(fi.FullName, tempFile);

                watermark.SaveProcessedImageToFileSystem(tempFile, fi.FullName);

                File.Delete(tempFile);
            }
        }
예제 #2
0
    protected void ProcessImage()
    {
        // Setup the source file name and the output file name
        string sourceImageFileName = this.imgSource.ImageUrl;
        string outputImageFileName = "~/repository/output/Ex_A_224.jpg";

        ImageWatermark imageWatermark = null;

        switch (this.ddlImageSource.SelectedIndex)
        {
        case 0:
            // piczardWatermark1.png
            // In this demo the image is automatically loaded/disposed by the ImageWatermark class
            imageWatermark = new ImageWatermark("~/repository/watermark/piczardWatermark1.png");

            imageWatermark.ContentAlignment    = (ContentAlignment)Enum.Parse(typeof(ContentAlignment), this.ddlContentAlignment.SelectedValue);
            imageWatermark.Unit                = (GfxUnit)Enum.Parse(typeof(GfxUnit), this.ddlMainUnit.SelectedValue);
            imageWatermark.ContentDisplacement = new Point(int.Parse(this.ddlContentDisplacementX.SelectedValue, CultureInfo.InvariantCulture), int.Parse(this.ddlContentDisplacementY.SelectedValue, CultureInfo.InvariantCulture));
            imageWatermark.Alpha               = int.Parse(this.ddlAlpha.SelectedValue, CultureInfo.InvariantCulture);

            // Process the image
            imageWatermark.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName);

            break;

        case 1:
            // codeCarvingsWatermark1.gif
            // In this demo the image is manually loaded/disposed (useful when you need to apply the same
            // watermark to multiple images)
            using (LoadedImage image = ImageArchiver.LoadImage("~/repository/watermark/codeCarvingsWatermark1.gif"))
            {
                imageWatermark = new ImageWatermark(image.Image);

                imageWatermark.ContentAlignment    = (ContentAlignment)Enum.Parse(typeof(ContentAlignment), this.ddlContentAlignment.SelectedValue);
                imageWatermark.Unit                = (GfxUnit)Enum.Parse(typeof(GfxUnit), this.ddlMainUnit.SelectedValue);
                imageWatermark.ContentDisplacement = new Point(int.Parse(this.ddlContentDisplacementX.SelectedValue, CultureInfo.InvariantCulture), int.Parse(this.ddlContentDisplacementY.SelectedValue, CultureInfo.InvariantCulture));
                imageWatermark.Alpha               = int.Parse(this.ddlAlpha.SelectedValue, CultureInfo.InvariantCulture);

                // Process the image
                imageWatermark.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName);
            }
            break;
        }

        // Update the displayed image (add a timestamp parameter to the query URL to ensure that the image is reloaded by the browser)
        this.imgOutput.ImageUrl = outputImageFileName + "?timestamp=" + DateTime.UtcNow.Ticks.ToString();

        // Display the generated image
        this.phOutputContainer.Visible = true;
    }
    protected void ProcessImage()
    {
        // Setup the source file name and the output file name
        string sourceImageFileName = this.imgSource.ImageUrl;
        string outputImageFileName = "~/repository/output/Ex_A_224.jpg";

        ImageWatermark imageWatermark = null;
        switch (this.ddlImageSource.SelectedIndex)
        {
            case 0:
                // piczardWatermark1.png
                // In this demo the image is automatically loaded/disposed by the ImageWatermark class
                imageWatermark = new ImageWatermark("~/repository/watermark/piczardWatermark1.png");

                imageWatermark.ContentAlignment = (ContentAlignment)Enum.Parse(typeof(ContentAlignment), this.ddlContentAlignment.SelectedValue);
                imageWatermark.Unit = (GfxUnit)Enum.Parse(typeof(GfxUnit), this.ddlMainUnit.SelectedValue);
                imageWatermark.ContentDisplacement = new Point(int.Parse(this.ddlContentDisplacementX.SelectedValue, CultureInfo.InvariantCulture), int.Parse(this.ddlContentDisplacementY.SelectedValue, CultureInfo.InvariantCulture));
                imageWatermark.Alpha = int.Parse(this.ddlAlpha.SelectedValue, CultureInfo.InvariantCulture);

                // Process the image
                imageWatermark.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName);

                break;
            case 1:
                // codeCarvingsWatermark1.gif
                // In this demo the image is manually loaded/disposed (useful when you need to apply the same
                // watermark to multiple images)
                using (LoadedImage image = ImageArchiver.LoadImage("~/repository/watermark/codeCarvingsWatermark1.gif"))
                {
                    imageWatermark = new ImageWatermark(image.Image);

                    imageWatermark.ContentAlignment = (ContentAlignment)Enum.Parse(typeof(ContentAlignment), this.ddlContentAlignment.SelectedValue);
                    imageWatermark.Unit = (GfxUnit)Enum.Parse(typeof(GfxUnit), this.ddlMainUnit.SelectedValue);
                    imageWatermark.ContentDisplacement = new Point(int.Parse(this.ddlContentDisplacementX.SelectedValue, CultureInfo.InvariantCulture), int.Parse(this.ddlContentDisplacementY.SelectedValue, CultureInfo.InvariantCulture));
                    imageWatermark.Alpha = int.Parse(this.ddlAlpha.SelectedValue, CultureInfo.InvariantCulture);

                    // Process the image
                    imageWatermark.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName);
                }
                break;
        }

        // Update the displayed image (add a timestamp parameter to the query URL to ensure that the image is reloaded by the browser)
        this.imgOutput.ImageUrl = outputImageFileName + "?timestamp=" + DateTime.UtcNow.Ticks.ToString();

        // Display the generated image
        this.phOutputContainer.Visible = true;
    }
예제 #4
0
        public ActionResult UploadPic(long houseId, HttpPostedFileBase file)
        {
            //一般是用文件的md5值来命名
            string fileMd5       = CommonHelper.CalcMd5(file.InputStream);
            string fileExt       = Path.GetExtension(file.FileName);
            string path          = "/upload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + fileMd5 + fileExt;
            string trumbPath     = "/upload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + fileMd5 + "_trumb" + fileExt;
            string trumbFullPath = Server.MapPath("~" + trumbPath);
            string fullPath      = Server.MapPath("~" + path);

            new FileInfo(trumbFullPath).Directory.Create();
            file.InputStream.Position = 0; //指针复位
            //缩略图
            ImageProcessingJob jobThumb = new ImageProcessingJob();

            jobThumb.Filters.Add(new FixedResizeConstraint(200, 200));//缩略图尺寸 200*200
            jobThumb.SaveProcessedImageToFileSystem(file.InputStream, trumbFullPath, new JpegFormatEncoderParams());

            file.InputStream.Position = 0; //指针复位
            ImageWatermark imgWatermark = new ImageWatermark(@"F:\86.jpg");

            imgWatermark.ContentAlignment = System.Drawing.ContentAlignment.BottomRight; //水印位置
            imgWatermark.Alpha            = 80;                                          //透明度,需要水印图片是背景透明的 png 图片
            ImageProcessingJob jobNormal = new ImageProcessingJob();

            jobNormal.Filters.Add(imgWatermark);//添加水印
            //jobNormal.Filters.Add(new FixedResizeConstraint(600, 600));//限制图片的大小,避免生成大图。如果想原图大小处理,就不用加这个 Filter然后调用 SaveProcessedImageToFileSystem 或者 SaveProcessedImageToStream 来保存文件
            imgWatermark.SaveProcessedImageToFileSystem(file.InputStream, fullPath, new JpegFormatEncoderParams());

            HouseService.AddNewHousePic(new HousePicDTO()
            {
                HouseId = houseId, Url = path, ThumbUrl = trumbPath
            });

            CreateStaticPages(houseId);//页面内容有变化,重新生成静态页
            return(Json(new AjaxResult()
            {
                Status = "ok"
            }));
        }