zoukankan      html  css  js  c++  java
  • Water Marked 水印

    from : Pro ASPnetMVCFramework

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.IO;
    
    namespace TestMvcWebApp1.ActionResultEx
    {
        public class WatermarkedImageResult : ActionResult
        {
            public WatermarkedImageResult() { }
            public string ImageFileName { get; private set; }
            public string WatermarkText { get; private set; }
            public WatermarkedImageResult(string imageFileName, string watermarkText)
            {
                ImageFileName = imageFileName;
                WatermarkText = watermarkText;
            }
            public override void ExecuteResult(ControllerContext context)
            {
                using (var image = Image.FromFile(ImageFileName))
                using (var graphics = Graphics.FromImage(image))
                using (var font = new Font("Arial", 10))
                using (var memoryStream = new MemoryStream())
                {
                    // Render the watermark text in bottom-left corner
                    var textSize = graphics.MeasureString(WatermarkText, font);
                    graphics.DrawString(WatermarkText, font, Brushes.Black, 10,
                        image.Height - textSize.Height - 10);
                    // Transmit the image in PNG format (note: must buffer it in
                    // memory first due to GDI+ limitation)284 CHAPTER 9 n CONTROLLERS AND ACTIONS
                    image.Save(memoryStream, ImageFormat.Png);
                    var response = context.RequestContext.HttpContext.Response;
                    response.ContentType = "image/png";
                    response.BinaryWrite(memoryStream.GetBuffer());
                }
            }
        }
    }
    
    

    使用:

     public ActionResult ViewmarkedImage()
            {
    
                string ImageFileName = @"C:\Documents and Settings\Administrator\My Documents\My Pictures\oem.gif";
                string WatermarkText = "这是我的水印";
                WatermarkedImageResult result = new WatermarkedImageResult(ImageFileName, WatermarkText);
                return result;
            }
    
  • 相关阅读:
    Pytorch版本yolov3源码阅读
    Darknet卷基层浅层特征可视化教程
    YOLOv3-darknet 内容解析
    YOLOv2-darknet 内容解析
    YOLOv1-darknet 内容解析
    Qt5.2+opencv2.4.9配置安装过程
    Android程序示例
    【Cuda编程】加法归约
    算法设计与分析课程的时间空间复杂度
    【算法分析】实验 4. 回溯法求解0-1背包等问题
  • 原文地址:https://www.cnblogs.com/wucg/p/1911465.html
Copyright © 2011-2022 走看看