<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      WatermarkMaker

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Drawing.Imaging;
      using System.Drawing;
      using System.IO;
      
      namespace TestUploadImage.FinalUse
      {
          public class WatermarkMaker
          {
              /// <summary>
              /// 圖片水印
              /// </summary>
              /// <param name="imgPath">服務(wù)器圖片相對路徑</param>
              /// <param name="filename">保存文件名</param>
              /// <param name="watermarkFilename">水印文件相對路徑</param>
              /// <param name="watermarkStatus">圖片水印位置 0=不使用 1=左上 2=中上 3=右上 4=左中  9=右下</param>
              /// <param name="quality">附加水印圖片質(zhì)量,0-100</param>
              /// <param name="watermarkTransparency">水印的透明度 1--10 10為不透明</param>
              public static void AddImageSignPic(string imgPath, string filename, string watermarkFilename, int watermarkStatus, int quality, int watermarkTransparency)
              {
                  if (!File.Exists(GetMapPath(imgPath)))
                      return;
                  byte[] _ImageBytes = File.ReadAllBytes(GetMapPath(imgPath));
                  Image img = Image.FromStream(new System.IO.MemoryStream(_ImageBytes));
                  filename = GetMapPath(filename);
      
                  if (watermarkFilename.StartsWith("/") == false)
                      watermarkFilename = "/" + watermarkFilename;
                  watermarkFilename = GetMapPath(watermarkFilename);
                  if (!File.Exists(watermarkFilename))
                      return;
                  Graphics g = Graphics.FromImage(img);
                  //設(shè)置高質(zhì)量插值法
                  //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
                  //設(shè)置高質(zhì)量,低速度呈現(xiàn)平滑程度
                  //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                  Image watermark = new Bitmap(watermarkFilename);
      
                  if (watermark.Height >= img.Height || watermark.Width >= img.Width)
                      return;
      
                  ImageAttributes imageAttributes = new ImageAttributes();
                  ColorMap colorMap = new ColorMap();
      
                  colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
                  colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
                  ColorMap[] remapTable = { colorMap };
      
                  imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
      
                  float transparency = 0.5F;
                  if (watermarkTransparency >= 1 && watermarkTransparency <= 10)
                      transparency = (watermarkTransparency / 10.0F);
      
      
                  float[][] colorMatrixElements = {
                                                      new float[] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f},
                                                      new float[] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f},
                                                      new float[] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f},
                                                      new float[] {0.0f,  0.0f,  0.0f,  transparency, 0.0f},
                                                      new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}
                                                  };
      
                  ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
      
                  imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
      
                  int xpos = 0;
                  int ypos = 0;
      
                  switch (watermarkStatus)
                  {//0 = 不使用 1 = 左上 2 = 中上 3 = 右上 4 = 左中  9 = 右下
                      case 1:
                          xpos = (int)(img.Width * (float).01);
                          ypos = (int)(img.Height * (float).01);
                          break;
                      case 2:
                          xpos = (int)((img.Width * (float).50) - (watermark.Width / 2));
                          ypos = (int)(img.Height * (float).01);
                          break;
                      case 3:
                          xpos = (int)((img.Width * (float).99) - (watermark.Width));
                          ypos = (int)(img.Height * (float).01);
                          break;
                      case 4:
                          xpos = (int)(img.Width * (float).01);
                          ypos = (int)((img.Height * (float).50) - (watermark.Height / 2));
                          break;
                      case 5:
                          xpos = (int)((img.Width * (float).50) - (watermark.Width / 2));
                          ypos = (int)((img.Height * (float).50) - (watermark.Height / 2));
                          break;
                      case 6:
                          xpos = (int)((img.Width * (float).99) - (watermark.Width));
                          ypos = (int)((img.Height * (float).50) - (watermark.Height / 2));
                          break;
                      case 7:
                          xpos = (int)(img.Width * (float).01);
                          ypos = (int)((img.Height * (float).99) - watermark.Height);
                          break;
                      case 8:
                          xpos = (int)((img.Width * (float).50) - (watermark.Width / 2));
                          ypos = (int)((img.Height * (float).99) - watermark.Height);
                          break;
                      case 9:
                          xpos = (int)((img.Width * (float).99) - (watermark.Width));
                          ypos = (int)((img.Height * (float).99) - watermark.Height);
                          break;
                  }
      
                  g.DrawImage(watermark, new Rectangle(xpos, ypos, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel, imageAttributes);
      
                  ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
                  ImageCodecInfo ici = null;
                  foreach (ImageCodecInfo codec in codecs)
                  {
                      if (codec.MimeType.IndexOf("jpeg") > -1)
                          ici = codec;
                  }
                  EncoderParameters encoderParams = new EncoderParameters();
                  long[] qualityParam = new long[1];
                  if (quality < 0 || quality > 100)
                      quality = 80;
      
                  qualityParam[0] = quality;
      
                  EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityParam);
                  encoderParams.Param[0] = encoderParam;
      
                  if (ici != null)
                      img.Save(filename, ici, encoderParams);
                  else
                      img.Save(filename);
      
                  g.Dispose();
                  img.Dispose();
                  watermark.Dispose();
                  imageAttributes.Dispose();
              }
      
              /// <summary>
              /// 文字水印
              /// </summary>
              /// <param name="imgPath">服務(wù)器圖片相對路徑</param>
              /// <param name="filename">保存文件名</param>
              /// <param name="watermarkText">水印文字</param>
              /// <param name="watermarkStatus">圖片水印位置 0=不使用 1=左上 2=中上 3=右上 4=左中  9=右下</param>
              /// <param name="quality">附加水印圖片質(zhì)量,0-100</param>
              /// <param name="fontname">字體</param>
              /// <param name="fontsize">字體大小</param>
              public static void AddImageSignText(string imgPath, string filename, string watermarkText, int watermarkStatus, int quality, string fontname, int fontsize)
              {
                  byte[] _ImageBytes = File.ReadAllBytes(GetMapPath(imgPath));
                  Image img = Image.FromStream(new System.IO.MemoryStream(_ImageBytes));
                  filename = GetMapPath(filename);
      
                  Graphics g = Graphics.FromImage(img);
                  Font drawFont = new Font(fontname, fontsize, FontStyle.Regular, GraphicsUnit.Pixel);
                  SizeF crSize;
                  crSize = g.MeasureString(watermarkText, drawFont);
      
                  float xpos = 0;
                  float ypos = 0;
      
                  switch (watermarkStatus)
                  {
                      case 1:
                          xpos = (float)img.Width * (float).01;
                          ypos = (float)img.Height * (float).01;
                          break;
                      case 2:
                          xpos = ((float)img.Width * (float).50) - (crSize.Width / 2);
                          ypos = (float)img.Height * (float).01;
                          break;
                      case 3:
                          xpos = ((float)img.Width * (float).99) - crSize.Width;
                          ypos = (float)img.Height * (float).01;
                          break;
                      case 4:
                          xpos = (float)img.Width * (float).01;
                          ypos = ((float)img.Height * (float).50) - (crSize.Height / 2);
                          break;
                      case 5:
                          xpos = ((float)img.Width * (float).50) - (crSize.Width / 2);
                          ypos = ((float)img.Height * (float).50) - (crSize.Height / 2);
                          break;
                      case 6:
                          xpos = ((float)img.Width * (float).99) - crSize.Width;
                          ypos = ((float)img.Height * (float).50) - (crSize.Height / 2);
                          break;
                      case 7:
                          xpos = (float)img.Width * (float).01;
                          ypos = ((float)img.Height * (float).99) - crSize.Height;
                          break;
                      case 8:
                          xpos = ((float)img.Width * (float).50) - (crSize.Width / 2);
                          ypos = ((float)img.Height * (float).99) - crSize.Height;
                          break;
                      case 9:
                          xpos = ((float)img.Width * (float).99) - crSize.Width;
                          ypos = ((float)img.Height * (float).99) - crSize.Height;
                          break;
                  }
      
                  g.DrawString(watermarkText, drawFont, new SolidBrush(Color.White), xpos + 1, ypos + 1);
                  g.DrawString(watermarkText, drawFont, new SolidBrush(Color.Black), xpos, ypos);
      
                  ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
                  ImageCodecInfo ici = null;
                  foreach (ImageCodecInfo codec in codecs)
                  {
                      if (codec.MimeType.IndexOf("jpeg") > -1)
                          ici = codec;
                  }
                  EncoderParameters encoderParams = new EncoderParameters();
                  long[] qualityParam = new long[1];
                  if (quality < 0 || quality > 100)
                      quality = 80;
      
                  qualityParam[0] = quality;
      
                  EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityParam);
                  encoderParams.Param[0] = encoderParam;
      
                  if (ici != null)
                      img.Save(filename, ici, encoderParams);
                  else
                      img.Save(filename);
      
                  g.Dispose();
                  img.Dispose();
              }
              #region 獲得當前絕對路徑
              /// <summary>
              /// 獲得當前絕對路徑
              /// </summary>
              /// <param name="strPath">指定的路徑</param>
              /// <returns>絕對路徑</returns>
              public static string GetMapPath(string strPath)
              {
                  if (strPath.ToLower().StartsWith("http://"))
                  {
                      return strPath;
                  }
                  if (HttpContext.Current != null)
                  {
                      string path = System.Web.HttpContext.Current.Server.MapPath("/") + strPath;
                      return path;
                  }
                  else //非web程序引用
                  {
                      strPath = strPath.Replace("/", "\\");
                      if (strPath.StartsWith("\\"))
                      {
                          strPath = strPath.Substring(strPath.IndexOf('\\', 1)).TrimStart('\\');
                      }
                      return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
                  }
              }
              #endregion
          }
      }

       

      posted @ 2018-11-16 15:16  CoderWayne  閱讀(370)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 一本久道久久综合中文字幕| 久久精品国产99国产精品严洲| AV无码不卡一区二区三区| 亚洲 自拍 另类 欧美 综合| 亚洲性图日本一区二区三区| 中文无码vr最新无码av专区| 亚洲在av极品无码天堂| 97在线视频人妻无码| 国产极品精品自在线不卡| 祁阳县| 亚洲黄色成人网在线观看| 26uuu另类亚洲欧美日本| 日韩a无v码在线播放| 虎白女粉嫩尤物福利视频| 亚洲日本韩国欧美云霸高清| 超碰人人超碰人人| 亚洲中文字幕精品一区二区三区| 日韩中av免费在线观看| 亚洲日韩性欧美中文字幕| 亚洲综合精品成人| 国产亚洲一区二区三区成人 | 精品亚洲精品日韩精品| 夜夜夜高潮夜夜爽夜夜爰爰| 好男人社区神马在线观看www| 精品无码久久久久久尤物| 丁香婷婷综合激情五月色| 国产农村老熟女国产老熟女 | 国产成人精品亚洲午夜麻豆 | 最新中文字幕国产精品| 国产精品亚洲аv无码播放| 日韩放荡少妇无码视频| 国产在线一区二区在线视频| 国产午夜精品理论大片| 高清国产av一区二区三区| 白城市| 午夜国产精品福利一二| 18禁亚洲一区二区三区| 国产美女自慰在线观看| 国产超高清麻豆精品传媒麻豆精品| 精品久久久久久无码中文野结衣| 亚洲熟女少妇乱色一区二区|