好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > asp.net如何在圖片上加水印文字具體實現

asp.net如何在圖片上加水印文字具體實現

熱門標簽:怎樣給陜西地圖標注顏色 廣州銷售外呼系統定制 400電話辦理信任翰諾科技 福州人工智能電銷機器人加盟 ai電銷機器人對貸款有幫助嗎 電銷機器人 數據 地圖標注多少錢一張 宿遷智能外呼系統排名 云狐人工智能電話機器人

第一步,添加一個一般處理程序(Handler),本例是ImageHandler

復制代碼 代碼如下:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mime;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

/// summary>
/// Summary description for ImageHandler
/// /summary>
public class ImageHandler : IHttpHandler
{
    public ImageHandler()
    {
    }

    public string GetContentType(String path)
    {
        switch (Path.GetExtension(path))
        {
            case ".bmp": return "Image/bmp";
            case ".gif": return "Image/gif";
            case ".jpg": return "Image/jpeg";
            case ".png": return "Image/png";
            default: break;
        }
        return String.Empty;
    }

    public ImageFormat GetImageFormat(String path)
    {
        switch (Path.GetExtension(path).ToLower())
        {
            case ".bmp": return ImageFormat.Bmp;
            case ".gif": return ImageFormat.Gif;
            case ".jpg": return ImageFormat.Jpeg;
            case ".png": return ImageFormat.Png;
            default: return null;
        }
    }

    protected byte[] WatermarkImage(HttpContext context)
    {

        byte[] imageBytes = null;
        if (File.Exists(context.Request.PhysicalPath))
        {
            // Normally you'd put this in a config file somewhere.
            string watermark = "世復檢測";

            Image image = Image.FromFile(context.Request.PhysicalPath);

            Graphics graphic;
            if (image.PixelFormat != PixelFormat.Indexed image.PixelFormat != PixelFormat.Format8bppIndexed image.PixelFormat != PixelFormat.Format4bppIndexed image.PixelFormat != PixelFormat.Format1bppIndexed)
            {
                // Graphic is not a Indexed (GIF) image
                graphic = Graphics.FromImage(image);
            }
            else
            {
                /* Cannot create a graphics object from an indexed (GIF) image.
                 * So we're going to copy the image into a new bitmap so
                 * we can work with it. */
                Bitmap indexedImage = new Bitmap(image);
                graphic = Graphics.FromImage(indexedImage);

                // Draw the contents of the original bitmap onto the new bitmap.
                graphic.DrawImage(image, 0, 0, image.Width, image.Height);
                image = indexedImage;
            }
            graphic.SmoothingMode = SmoothingMode.AntiAlias SmoothingMode.HighQuality;

            Font myFont = new Font("Arial", 15);
            SolidBrush brush = new SolidBrush(Color.FromArgb(255, Color.Red));

            /* This gets the size of the graphic so we can determine
             * the loop counts and placement of the watermarked text. */
            SizeF textSize = graphic.MeasureString(watermark, myFont);

            //// Write the text across the image.
            //for (int y = 0; y image.Height; y++)
            //{
            //    for (int x = 0; x image.Width; x++)
            //    {
            //        PointF pointF = new PointF(x, y);
            //        graphic.DrawString(watermark, myFont, brush, pointF);
            //        x += Convert.ToInt32(textSize.Width);
            //    }
            //    y += Convert.ToInt32(textSize.Height);
            //}


            // Write the text at the right bottom of the image.
            for (int y = image.Height-25; y image.Height; y++)
            {
                for (int x = image.Width-100; x image.Width; x++)
                {
                    PointF pointF = new PointF(x, y);
                    graphic.DrawString(watermark, myFont, brush, pointF);
                    x += Convert.ToInt32(textSize.Width);
                }
                y += Convert.ToInt32(textSize.Height);
            }

            using (MemoryStream memoryStream = new MemoryStream())
            {
                image.Save(memoryStream, GetImageFormat(context.Request.PhysicalPath));
                imageBytes = memoryStream.ToArray();
            }

        }
        return imageBytes;
    }

    #region IHttpHandler Members

    public bool IsReusable
    {
        get { return false; }
    }

    public void ProcessRequest(HttpContext context)
    {
        context.Response.Clear();
        context.Response.ContentType = GetContentType(context.Request.PhysicalPath);
        byte[] imageBytes = WatermarkImage(context);
        if (imageBytes != null)
        {
            context.Response.OutputStream.Write(imageBytes, 0, imageBytes.Length);
        }
        else
        {
            // No bytes = no image which equals NO FILE.   
            // Therefore send a 404 - not found response.
            context.Response.StatusCode = 404;
        }
        context.Response.End();
    }

    #endregion
}

第二步,在web.config里添加如下代碼:

復制代碼 代碼如下:

    httpHandlers>
      !--add verb="GET" type="ImageHandler" path="*.jpg,*.png,*.gif,*.bmp"/>-->
      add verb="GET" type="ImageHandler" path="Uploads/*/*.jpg"/>     
    /httpHandlers>

您可能感興趣的文章:
  • 如何在ASP.NET Core中給上傳圖片功能添加水印實例代碼
  • ASP.NET百度Ueditor編輯器實現上傳圖片添加水印效果
  • Asp.net開發(fā)之webform圖片水印和圖片驗證碼的實現方法
  • asp.net繼承IHttpHandler接口實現給網站圖片添加水印功能實例
  • ASP.NET簡單好用功能齊全圖片上傳工具類(水印、縮略圖、裁剪等)
  • Asp.net簡單實現給圖片增加文字水印
  • asp.net上傳圖片并作處理水印與縮略圖的實例代碼
  • ASP.NET 圖片加水印防盜鏈實現代碼
  • asp.net中上傳圖片文件實現防偽圖片水印并寫入數據庫
  • ASP.NET實現圖片自動添加水印

標簽:宜春 綿陽 延安 大興安嶺 黃南 曲靖 焦作 新疆

巨人網絡通訊聲明:本文標題《asp.net如何在圖片上加水印文字具體實現》,本文關鍵詞  asp.net,如,何在,圖片,上加,;如發(fā)現本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《asp.net如何在圖片上加水印文字具體實現》相關的同類信息!
  • 本頁收集關于asp.net如何在圖片上加水印文字具體實現的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 91成人??在线观看喷潮| 国产成人精品三上悠亚久久| 翁虹三级伦理电影大全在线观看| 很黄很肉很刺激的小说推荐| a级在线观看视频| 91精品国产高清久久久久久io| 国产视频一二三区| 波野吉多电影在线观看| 摸进女同桌的小内裤狂摸里 | 扒开臀缝撅好打烂| 李采潭一级毛片高清免费观看 | 性之剧| 男校公用便器hhh夏苒苒| 91在线精品无码秘?入口软件| 日韩色图在线| 三级高清理伦电影在线| 男生舔女生逼| 亚洲AV无码乱码精品国产潘金莲| japanesexxxxx护士| 被迫在刑具上高潮调教道具| 日韩人妻无码一区二区三区久久99| 老扒夜夜春宵第一部的| 久久久久久精品无码国语婚闹| 免费女女乱婬视频在线观看| 丰满的?子2理论视频在线观看| 精品综合久久久久97| 性久久久久久久久久| 女人炮约用什么app| 虎虎影院| 好男人社区在线www影视| 成人片男男在线看| 少妇一级婬片免放99久久蜜Av| 性瘾难戒(NP,粗口,黄暴)简体| 亚洲国产第一区| 精品久久久久久中文字幕人妻日本 | 亚洲国产精品国自产拍色欲| 夜夜夜AV视频一二三区| 直男被室友cao到哭高H| 爽爽窝窝午夜精品一区| yw193.c㎝国产在线播放| 一边吃奶一边摸一边做|