永发信息网

谁能给个asp.net的图片水印源码啊

答案:1  悬赏:50  手机版
解决时间 2021-02-14 18:11
累死于下图图片水印效果;514523596@qq.com谢谢了 正常使用的加分。。
最佳答案
System;/ <.Drawing2D;param>
/.ToCharArray())[1]; System.Drawing.Graphics g = System.Drawing.Graphics; break;
case ".Drawing, new System;//param>
/, System;>.Image oldimage = System.Width;裁剪方式:hw指定高宽缩放(自动分析长宽比)、w指定宽;
//.Imaging;
//
public class ImgHelper
{
/>,
0;//.Height);param name="width"JPEG"param name="left">左边位置 {
file;
//
break;:
oldimage;宽 System.Drawing.Image copyImage = System.DrawImage(copyImage;返回经过处理后的文件名 {
case "/param>.", System.Imaging;
using System.IO;
break;
g, string Path_sypf)
{
string FileName = filename(file);
using System.Drawing;
using System, copyImage.Height;
// break.Rectangle(oldimage.Width - copyImage.Width,
oldimage;版权信息<, int width, int height, string mode.Drawing;
using System.Web.UI.Drawing.Drawing;/ <,宽按比例、cut指定高宽裁减<,高按比例、h指定高;returns>
public static string GetSamilImageAddCopyrightByImg(string path, FileUpload file.PostedFile.SaveAs(path + FileName);/, copyImage.Width, copyImage, 0, copyImage;param>
/>
string YFileName = "y_" + FileName;
switch (file;param name="path">要保存的实际路径上边位置 oldimageusing System;//>/保存原图
System;param>
/.Height - copyImage.Height.Save(path + YFileName;
Path_sypf = path + Path_sypf;
if (File.Drawing;mode"aspx页面中的上传控件<.PostedFile.FileName.GraphicsUnit.Pixel);
/// <:
oldimage.Drawing;/
using System.Web;
using System.UI.HtmlControls;PNG".Imaging:
oldimage.Save(path + YFileName, System.Drawing.Imaging.ImageFormat.Png).Image.Drawing;/summary>.Save(path + YFileName;
case "BMP":
oldimage.Save(path + YFileName, System.Drawing.Imaging.ImageFormat.Bmp);
break;
default:
oldimage.Save(path + YFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
}
int towidth = width;
int toheight = height;
int x = 0;
int y = 0;
int ow = oldimage.Width;
int oh = oldimage.Height;
float owh = ((float)ow) / ((float)oh);
switch (mode)
{
case "hw"://指定高宽缩放(自动分析长宽比)
if (ow >= oh)
{
towidth = width;
toheight = Convert.ToInt32((float)towidth / owh);
}
else
{
toheight = height;
towidth = Convert.ToInt32((float)toheight * owh);
}
break;
case "w"://指定宽,高按比例
toheight = oldimage.Height * width / oldimage.Width;
break;
case "h"://指定高,宽按比例
towidth = oldimage.Width * height / oldimage.Height;
break;
case "cut"://指定高宽裁减(不变形)
if ((double)oldimage.Width / (double)oldimage.Height > (double)towidth / (double)toheight)
{
oh = oldimage.Height;
ow = oldimage.Height * towidth / toheight;
y = 0;
x = (oldimage.Width - ow) / 2;
}
else
{
ow = oldimage.Width;
oh = oldimage.Width * height / towidth;
x = 0;
y = (oldimage.Height - oh) / 2;
}
break;
default:
break;
}
//新建一个bmp图片,并制定宽高
System.Drawing.Image thumbnailImage = new System.Drawing.Bitmap(towidth, toheight);
//新建一个画板
Graphics newpic = System.Drawing.Graphics.FromImage(thumbnailImage);
//设置高质量插值法
newpic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
newpic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//清空画布并以透明背景色填充
newpic.Clear(Color.Transparent);
//在指定位置并且按指定大小绘制原图片的指定部分
newpic.DrawImage(oldimage, new Rectangle(0, 0, towidth, toheight),
new Rectangle(x, y, ow, oh), GraphicsUnit.Pixel);
string S_FileName = "s_" + FileName;
switch (file.PostedFile.FileName.Split(".".ToCharArray())[1].ToUpper())
{
case "JPEG":
case "JPG":
thumbnailImage.Save(path + S_FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case "GIF":
thumbnailImage.Save(path + S_FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case "PNG":
thumbnailImage.Save(path + S_FileName, System.Drawing.Imaging.ImageFormat.Png);
break;
case "BMP":
thumbnailImage.Save(path + S_FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
default:
thumbnailImage.Save(path + S_FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
}
thumbnailImage.Dispose();
copyImage.Dispose();
g.Dispose();
oldimage.Dispose();
File.Delete(path + FileName);
return S_FileName;//返回处理后的图片名称
}
else//如果图片已经存在则返回""
{
return "";
}
}
///
/// 生成文件名(包括路径)
///

/// 上传控件
/// 上传到的目录
/// 根据当前时间并加入随机数
public static string filename(FileUpload file)
{
//得到当前时间精确到毫秒
string FileName = DateTime.Now.ToString("yyMMddHHmmss") + DateTime.Now.Millisecond.ToString();
//得到随机数
char[] s = new char[]{'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G'
,'J','K','L','M','N','P','Q','R','T','U','V','W'
,'X','Z'};
string num = "";
Random r = new Random();
for (int i = 0; i < 6; i++)
{
num += s[r.Next(0, s.Length - 1)].ToString();
}
//得到文件上传路径
string[] FileSrc = file.PostedFile.FileName.Split(@"\".ToCharArray());
string YFileName = FileSrc[FileSrc.Length - 1];
//得到文件扩展名
string FileEx = YFileName.Split('.')[1].ToUpper();
//得到文件名并返回
return FileName + num + "." + FileEx;
}
};>.Save(path + YFileName;/ 功能生成小图,+版权信息(图片水印)
//
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
东扬威胡同/东羊管胡同(路口)地址在什么地方
洁白的栀子花作者
【六月开什么花】六月花开 作文
请问运动鞋的后鞋跟有点烧焦了,有什么办法可
瓷砖粘合剂和水泥有什么区别
华亿连锁超市安靖店周华亿副食店在什么地方啊
导演专业前途怎样?
华为手机不停采集信息怎么办
中国农业银行24小时自助银行(哈尔滨延兴分理
战网 一个身份证可以绑定几个帐号?
野猪跟藏獒打架哪个厉害?
阳光教育信息咨询中心地址在哪,我要去那里办
海洋深处绿色植物很难生存,主要是缺少植物生
我的目光为一群音乐演奏者所吸引的为 是什么
有多少人叫付海艳
推荐资讯
老婆背着我在外欠款我怎么办
龙组!真的有吗?
民国耽美小说
静心源茶艺馆地址在什么地方,我要处理点事
驾校站岗要站几个小时
黄渤到上海学厨师是什么电影
新港快餐我想知道这个在什么地方
种蒜苗作文的开头和结尾
女生游戏名字,沐?雨,三个字中间那个用个什
请问连云港东站就是墟沟吗?那么墟沟离花果山
中国信合(朝阳分社)(朝阳路与重阳大道交叉口
手机质量问题,店里不给换,怎么办?12315?
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?