亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

修改

系統 1825 0

using System;using System.Collections.Generic;using System.Collections;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.IO;using System.Drawing;using System.Threading;using System.Drawing.Imaging;
using DotNetNuke;using DotNetNuke.Common.Utilities;using DotNetNuke.Security;using DotNetNuke.Services.Exceptions;using DotNetNuke.Services.Localization;using DotNetNuke.Entities.Modules;using DotNetNuke.Entities.Modules.Actions;using Telerik.Web.UI;

?


namespace xyz_CarPT{?? ?public partial class BatchWatermarkfight : PortalModuleBase, IActionable?? ?{
?? ? ? ?#region "Optional Interfaces"
?? ? ? ?/// -----------------------------------------------------------------------------??? ? ? ?/// <summary>??? ? ? ?/// Registers the module actions required for interfacing with the portal framework??? ? ? ?/// </summary>??? ? ? ?/// <value></value>??? ? ? ?/// <returns></returns>??? ? ? ?/// <remarks></remarks>??? ? ? ?/// <history>??? ? ? ?/// </history>??? ? ? ?/// -----------------------------------------------------------------------------??? ? ? ?public ModuleActionCollection ModuleActions?? ? ? ?{?? ? ? ? ? ?get?? ? ? ? ? ?{?? ? ? ? ? ? ? ?ModuleActionCollection Actions = new ModuleActionCollection();?? ? ? ? ? ? ? ?Actions.Add(GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, this.LocalResourceFile),?? ? ? ? ? ? ? ? ? ModuleActionType.AddContent, "", "add.gif", EditUrl(), false, DotNetNuke.Security.SecurityAccessLevel.Edit,?? ? ? ? ? ? ? ? ? ?true, false);?? ? ? ? ? ? ? ?return Actions;?? ? ? ? ? ?}?? ? ? ?}?? ? ? ?#endregion?? ? ? ?protected void Page_Load(object sender, EventArgs e)?? ? ? ?{?? ? ? ? ? ?if (!Page.IsPostBack)?? ? ? ? ? ?{?? ? ? ? ? ? ? ?GetWatermark(DropDownList1);?? ? ? ? ? ?}
?? ? ? ?}
?? ? ? ?public void GetWatermark(DropDownList combox)??? ? ? ?{?? ? ? ? ? ?if (!Page.IsPostBack)?? ? ? ? ? ?{?? ? ? ? ? ? ? ?string path = Server.MapPath(".") + "\\Portals\\_default\\Skins\\xyz_akd\\img\\CarsPhoto\\Watermark\\";?? ? ? ? ? ? ? ?string[] files = Directory.GetFiles(path);?? ? ? ? ? ? ? ?List<string> fileslist = new List<string>();?? ? ? ? ? ? ? ?DropDownList combobox = combox;?? ? ? ? ? ? ? ?int i = 0;?? ? ? ? ? ? ? ?for (i = 0; i < files.Length; i++)?? ? ? ? ? ? ? ?{?? ? ? ? ? ? ? ? ? ?string oimg = files[i].ToString();?? ? ? ? ? ? ? ? ? ?if (IsImg(oimg))?? ? ? ? ? ? ? ? ? ?{?? ? ? ? ? ? ? ? ? ? ? ?fileslist.Add(oimg);?? ? ? ? ? ? ? ? ? ?}?? ? ? ? ? ? ? ?}?? ? ? ? ? ? ? ?combobox.DataSource = fileslist;?? ? ? ? ? ? ? ?combobox.DataBind();?? ? ? ? ? ?}?? ? ? ?}
?? ? ? ?protected void Button1_Click(object sender, EventArgs e)?? ? ? ?{?? ? ? ? ? ?string path = Server.MapPath(".") + "\\Portals\\_default\\Skins\\xyz_akd\\img\\CarsPhoto\\showcar2\\"; //圖片文件夾;?? ? ? ? ? ?string[] files = Directory.GetFiles(path); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//獲得圖片文件夾下所有圖片?? ? ? ? ? ?string watchwatermarkurl = DropDownList1.SelectedValue.ToString(); ? ? ? ? ? ? ? ? ? ? ?//水印圖片路徑?? ? ? ? ? ?string saveimgurl = "\\Portals\\_default\\Skins\\xyz_akd\\img\\CarsPhoto\\showcar2"; ? ?//新圖片保存的路徑?? ? ? ? ? ?int i = 0;?? ? ? ? ? ?for(i=0;i<files.Length;i++)?? ? ? ? ? ?{?? ? ? ? ? ? ? ?string oimg = files[i].ToString();?? ? ? ? ? ? ? ?if (i % 100 == 0)?? ? ? ? ? ? ? ?{?? ? ? ? ? ? ? ? ? ?Thread.Sleep(10);?? ? ? ? ? ? ? ? ? ?GC.Collect();?? ? ? ? ? ? ? ?}?? ? ? ? ? ? ? ?if (IsImg(oimg))?? ? ? ? ? ? ? ?{
?? ? ? ? ? ? ? ? ? ?if (!oimg.Contains("_0_"))?? ? ? ? ? ? ? ? ? ?{?? ? ? ? ? ? ? ? ? ? ? ?try?? ? ? ? ? ? ? ? ? ? ? ?{?? ? ? ? ? ? ? ? ? ? ? ? ? ?batchwater(oimg, watchwatermarkurl,saveimgurl);?? ? ? ? ? ? ? ? ? ? ? ?}catch(Exception ex)?? ? ? ? ? ? ? ? ? ? ? ?{?? ? ? ? ? ? ? ? ? ? ? ? ? ?Console.WriteLine(ex.ToString()); ? ??? ? ? ? ? ? ? ? ? ? ? ?}?? ? ? ? ? ? ? ? ? ?}?? ? ? ? ? ? ? ?}?? ? ? ? ? ?}?? ? ? ?}


?? ? ? ?private void batchwater(string imgurl,string imgurl2,string saveimgurl)?? ? ? ?{?? ? ? ? ? ?if (imgurl != "" && imgurl2 != "")?? ? ? ? ? ?{?? ? ? ? ? ? ? ?//加圖片水印?? ? ? ? ? ? ? ?System.Drawing.Image image = System.Drawing.Image.FromFile(imgurl);?? ? ? ? ? ? ? ?System.Drawing.Image copyImage = System.Drawing.Image.FromFile(imgurl2); //FromFile(Server.MapPath(".") + imgurl2);?? ? ? ? ? ? ? ?Graphics g = Graphics.FromImage(image);?? ? ? ? ? ? ? ?g.DrawImage(copyImage, new Rectangle(image.Width - copyImage.Width, image.Height - copyImage.Height, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);?? ? ? ? ? ? ? ?g.Dispose();?? ? ? ? ? ? ? ?//保存加水印過后的圖片"?? ? ? ? ? ? ? ?string path = Server.MapPath(".") + saveimgurl;?? ? ? ? ? ? ? ?string newPath = path+imgurl.Substring(imgurl.LastIndexOf("\\"));?? ? ? ? ? ? ? ?if (File.Exists(newPath)) {?? ? ? ? ? ? ? ? ? ?File.Delete(newPath);?? ? ? ? ? ? ? ?}?? ? ? ? ? ? ? ?image.Save(newPath);?? ? ? ? ? ? ? ?copyImage.Dispose();?? ? ? ? ? ? ? ?image.Dispose();?? ? ? ? ? ?}?? ? ? ?}

?

?? ? ? ?//using System.Drawing; ??? ? ? ?//using System.IO; ??? ? ? ?//using System.Drawing.Imaging; ?
?? ? ? ?private void AddTextToImg(string fileName, string text)?? ? ? ?{?? ? ? ? ? ?if (!File.Exists(fileName))?? ? ? ? ? ?{?? ? ? ? ? ? ? ?throw new FileNotFoundException("The file don't exist!");?? ? ? ? ? ?}
?? ? ? ? ? ?if (text == string.Empty)?? ? ? ? ? ?{?? ? ? ? ? ? ? ?return;?? ? ? ? ? ?}?? ? ? ? ? ?//還需要判斷文件類型是否為圖像類型,這里就不贅述了 ?
?? ? ? ? ? ?System.Drawing.Image image = System.Drawing.Image.FromFile(fileName);?? ? ? ? ? ?Bitmap bitmap = new Bitmap(image, image.Width, image.Height);?? ? ? ? ? ?Graphics g = Graphics.FromImage(bitmap);
?? ? ? ? ? ?float fontSize = 12.0f; ? ?//字體大小 ??? ? ? ? ? ?float textWidth = text.Length * fontSize; ?//文本的長度 ??? ? ? ? ? ?//下面定義一個矩形區域,以后在這個矩形里畫上白底黑字 ??? ? ? ? ? ?float rectX = 0;?? ? ? ? ? ?float rectY = 0;?? ? ? ? ? ?float rectWidth = text.Length * (fontSize + 8);?? ? ? ? ? ?float rectHeight = fontSize + 8;?? ? ? ? ? ?//聲明矩形域 ??? ? ? ? ? ?RectangleF textArea = new RectangleF(rectX, rectY, rectWidth, rectHeight);
?? ? ? ? ? ?Font font = new Font("宋體", fontSize); ? //定義字體 ??? ? ? ? ? ?Brush whiteBrush = new SolidBrush(Color.White); ? //白筆刷,畫文字用 ??? ? ? ? ? ?Brush blackBrush = new SolidBrush(Color.Black); ? //黑筆刷,畫背景用 ?
?? ? ? ? ? ?g.FillRectangle(blackBrush, rectX, rectY, rectWidth, rectHeight);
?? ? ? ? ? ?g.DrawString(text, font, whiteBrush, textArea);?? ? ? ? ? ?MemoryStream ms = new MemoryStream();?? ? ? ? ? ?//保存為Jpg類型 ??? ? ? ? ? ?bitmap.Save(ms, ImageFormat.Jpeg);
?? ? ? ? ? ?//輸出處理后的圖像,這里為了演示方便,我將圖片顯示在頁面中了 ??? ? ? ? ? ?Response.Clear();?? ? ? ? ? ?Response.ContentType = "image/jpeg";?? ? ? ? ? ?Response.BinaryWrite(ms.ToArray());
?? ? ? ? ? ?g.Dispose();?? ? ? ? ? ?bitmap.Dispose();?? ? ? ? ? ?image.Dispose();?? ? ? ?} ?
?? ? ? ?#region ?判斷文件是否為圖片?? ? ? ?/// </summary>?? ? ? ?/// <param name="filePath">filePath</param>?? ? ? ?/// <returns></returns>?? ? ? ?public static bool IsImg(string filePath)?? ? ? ?{?? ? ? ? ? ?bool v = false;?? ? ? ? ? ?if (File.Exists(filePath))?? ? ? ? ? ?{?? ? ? ? ? ? ? ?try?? ? ? ? ? ? ? ?{?? ? ? ? ? ? ? ? ? ?FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);?? ? ? ? ? ? ? ? ? ?BinaryReader reader = new BinaryReader(fs);?? ? ? ? ? ? ? ? ? ?string fileClass;?? ? ? ? ? ? ? ? ? ?byte buffer;?? ? ? ? ? ? ? ? ? ?byte[] b = new byte[2];?? ? ? ? ? ? ? ? ? ?buffer = reader.ReadByte();?? ? ? ? ? ? ? ? ? ?b[0] = buffer;?? ? ? ? ? ? ? ? ? ?fileClass = buffer.ToString();?? ? ? ? ? ? ? ? ? ?buffer = reader.ReadByte();?? ? ? ? ? ? ? ? ? ?b[1] = buffer;?? ? ? ? ? ? ? ? ? ?fileClass += buffer.ToString();?? ? ? ? ? ? ? ? ? ?reader.Close();?? ? ? ? ? ? ? ? ? ?fs.Close();?? ? ? ? ? ? ? ? ? ?//255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar ???? ? ? ? ? ? ? ? ? ?if (fileClass == "255216" || fileClass == "7173" || fileClass == "6677" || fileClass == "13780")?? ? ? ? ? ? ? ? ? ?{?? ? ? ? ? ? ? ? ? ? ? ?v = true;?? ? ? ? ? ? ? ? ? ?}?? ? ? ? ? ? ? ? ? ?else?? ? ? ? ? ? ? ? ? ?{?? ? ? ? ? ? ? ? ? ? ? ?v = false;?? ? ? ? ? ? ? ? ? ?}?? ? ? ? ? ? ? ?}?? ? ? ? ? ? ? ?catch?? ? ? ? ? ? ? ?{?? ? ? ? ? ? ? ? ? ?v = false;?? ? ? ? ? ? ? ?}?? ? ? ? ? ?}?? ? ? ? ? ?else?? ? ? ? ? ?{?? ? ? ? ? ? ? ?v = false;?? ? ? ? ? ?}?? ? ? ? ? ?return v;?? ? ? ?}?? ? ? ?#endregion
?? ? ? ?protected void Button2_Click(object sender, EventArgs e)?? ? ? ?{?? ? ? ? ? ?AddTextToImg(Server.MapPath(".") + "\\Portals\\_default\\Skins\\xyz_akd\\img\\CarsPhoto\\showcar2\\27_2_9.jpg","sikaodelang");?? ? ? ?}
?? ?}}

修改


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 精品欧美一区手机在线观看 | 欧美日韩国产58香蕉在线视频 | 五月婷婷视频在线观看 | 成人午夜久久精品 | 一本久道久综合久久鬼色 | 在线观看偷拍视频一区 | 四虎a级欧美在线观看 | 成人毛片免费在线观看 | 欧美v在线 | 欧美一级片免费 | 性一级录像 | 在线播放精品一区二区啪视频 | 久久精品国产亚洲 | 在线观看国产一区 | 久久精品区| 天天干天天天天 | 国产成人a大片大片在线播放 | 日韩视频在线观看一区二区 | 四虎地址8848jia | 久久尹人 | 天天插天天射 | 深夜在线免费观看 | 免费一级特黄 欧美大片 | 中文字幕免费在线 | 9久9久女女热精品视频免费观看 | 这里只有精品视频 | 青青青国产精品手机在线观看 | 久草最新在线 | 级毛片| 日韩经典欧美精品一区 | 麻豆视频一区二区 | 中国日韩欧美中文日韩欧美色 | 97最新 | 五月天婷婷在线观看高清 | 成人在线亚洲 | 香蕉视频国产 | 狠狠干天天| 日本一级毛片大片免费 | xxxxx日本59| 久久久久久青草大香综合精品 | 九九精品视频在线免费观看 |