public partial class WebForm4 : System.Web.UI.Page
{
// 原始图片路径
private string path;
private System.Drawing.Bitmap bitmap;
private System.Drawing.Graphics graphics;
string Message = "<script>alert(\"{0}\");</script>";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.txtPicPath.Text = Server.MapPath("/test.jpg");
}
path = this.txtPicPath.Text.Trim();
if (!System.IO.File.Exists(path))
{
MessageShow("指定的源文件不存在!");
return;
}
}
// 打水印Logo
protected void btnLogo_Click(object sender, EventArgs e)
{
string log = txtLog.Text.Trim();
if (log.Length < 1)
{
MessageShow("请输入水印字符!");
return;
}
bitmap = new Bitmap(path);
graphics = Graphics.FromImage(bitmap);
graphics.DrawString(log, new Font("宋体", 16), System.Drawing.Brushes.GreenYellow, new PointF(bitmap.Width / 2 - (log.Length) * 5, bitmap.Height / 2));
try
{
bitmap.Save(Server.MapPath("./_Log.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
MessageShow("已经生成水印图片,路径为" + @Server.MapPath("./_log.jpg").Replace("\\", "\\\\"));
}
catch (Exception ex)
{
MessageShow("生成图片错误!" + ex.Message);
throw;
}
graphics.Dispose();
bitmap.Dispose();
}
private void MessageShow(string msg)
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "Message", string.Format(Message, msg));
}
//放大X*X倍
protected void btnBig_Click(object sender, EventArgs e)
{
int i = int.Parse(txtBig.Text.Trim());
System.Drawing.Image img = System.Drawing.Image.FromFile(path);
bitmap = new Bitmap(img.Width * i, img.Height * i);
graphics = Graphics.FromImage(bitmap);
graphics.DrawImage(img, 0, 0, img.Width * i, img.Height * i);
try
{
bitmap.Save(Server.MapPath("./_Big.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
MessageShow("已经生成图片,路径为" + @Server.MapPath("./_Big.jpg").Replace("\\", "\\\\"));
}
catch (Exception ex)
{
MessageShow("生成图片错误!" + ex.Message);
throw;
}
graphics.Dispose();
bitmap.Dispose();
}
//缩小为原始图像的1/(X*X)
protected void btnSmall_Click(object sender, EventArgs e)
{
float i = float.Parse(txtBig.Text.Trim());
System.Drawing.Image img = System.Drawing.Image.FromFile(path);
int w = Convert.ToInt32(img.Width / i);
int h = Convert.ToInt32(img.Height / i);
// 防止过度变形
if (w < 1) w = 10;
if (h < 1) h = 0;
bitmap = new Bitmap(w, h);
graphics = Graphics.FromImage(bitmap);
graphics.DrawImage(img, 0, 0, w, h);
try
{
bitmap.Save(Server.MapPath("./_Small.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
MessageShow("已经生成图片,路径为" + @Server.MapPath("./_Small.jpg").Replace("\\", "\\\\"));
}
catch (Exception ex)
{
MessageShow("生成图片错误!" + ex.Message);
throw;
}
graphics.Dispose();
bitmap.Dispose();
}
//倾斜( 右转90度)
protected void btnIncline_Click(object sender, EventArgs e)
{
System.Drawing.Image img = System.Drawing.Image.FromFile(path);
// 图像旋转,可以利用RotateFlipType的枚举值,在编程的时候,IDE会自动显示每一个枚举的意思
img.RotateFlip(RotateFlipType.Rotate90FlipXY);
bitmap = new Bitmap(img);
graphics = Graphics.FromImage(bitmap);
graphics.DrawImage(img, new Point(0, 0));
try
{
bitmap.Save(Server.MapPath("./_Incline.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
MessageShow("已经生成图片,路径为" + @Server.MapPath("./_Incline.jpg").Replace("\\", "\\\\"));
}
catch (Exception ex)
{
MessageShow("生成图片错误!" + ex.Message);
throw;
}
graphics.Dispose();
bitmap.Dispose();
}
// 图像压扁
protected void btnStave_Click(object sender, EventArgs e)
{
System.Drawing.Image img = System.Drawing.Image.FromFile(path);
// 宽度不变
int w = img.Width;
// 高度为原始高度的1/2
int h = img.Height / 2;
// 防止过度变形
if (w < 1) w = 10;
if (h < 1) h = 0;
bitmap = new Bitmap(w, h);
graphics = Graphics.FromImage(bitmap);
graphics.DrawImage(img, 0, 0, w, h);
try
{
bitmap.Save(Server.MapPath("./_Stave.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
MessageShow("已经生成图片,路径为" + @Server.MapPath("./_Stave.jpg").Replace("\\", "\\\\"));
}
catch (Exception ex)
{
MessageShow("生成图片错误!" + ex.Message);
throw;
}
graphics.Dispose();
bitmap.Dispose();
}
//图像拉宽
protected void btnElongate_Click(object sender, EventArgs e)
{
System.Drawing.Image img = System.Drawing.Image.FromFile(path);
// 放大宽度
int w = img.Width / 2;
// 高度不变
int h = img.Height;
// 防止过度变形
if (w < 1) w = 10;
if (h < 1) h = 0;
bitmap = new Bitmap(w, h);
graphics = Graphics.FromImage(bitmap);
graphics.DrawImage(img, 0, 0, w, h);
try
{
bitmap.Save(Server.MapPath("./_Elongate.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
MessageShow("已经生成图片,路径为" + @Server.MapPath("./_Elongate.jpg").Replace("\\", "\\\\"));
}
catch (Exception ex)
{
MessageShow("生成图片错误!" + ex.Message);
throw;
}
graphics.Dispose();
bitmap.Dispose();
}
}
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]