ASP.NET 2.0,C#----圖像特效處理
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("請(qǐng)輸入水印字符!");
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("已經(jīng)生成水印圖片,路徑為" + @Server.MapPath("./_log.jpg").Replace("\\", "\\\\"));
}
catch (Exception ex)
{
MessageShow("生成圖片錯(cuò)誤!" + 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("已經(jīng)生成圖片,路徑為" + @Server.MapPath("./_Big.jpg").Replace("\\", "\\\\"));
}
catch (Exception ex)
{
MessageShow("生成圖片錯(cuò)誤!" + 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("已經(jīng)生成圖片,路徑為" + @Server.MapPath("./_Small.jpg").Replace("\\", "\\\\"));
}
catch (Exception ex)
{
MessageShow("生成圖片錯(cuò)誤!" + ex.Message);
throw;
}
graphics.Dispose();
bitmap.Dispose();
}
//傾斜( 右轉(zhuǎn)90度)
protected void btnIncline_Click(object sender, EventArgs e)
{
System.Drawing.Image img = System.Drawing.Image.FromFile(path);
// 圖像旋轉(zhuǎn),可以利用RotateFlipType的枚舉值,在編程的時(shí)候,IDE會(huì)自動(dòng)顯示每一個(gè)枚舉的意思
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("已經(jīng)生成圖片,路徑為" + @Server.MapPath("./_Incline.jpg").Replace("\\", "\\\\"));
}
catch (Exception ex)
{
MessageShow("生成圖片錯(cuò)誤!" + 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("已經(jīng)生成圖片,路徑為" + @Server.MapPath("./_Stave.jpg").Replace("\\", "\\\\"));
}
catch (Exception ex)
{
MessageShow("生成圖片錯(cuò)誤!" + 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("已經(jīng)生成圖片,路徑為" + @Server.MapPath("./_Elongate.jpg").Replace("\\", "\\\\"));
}
catch (Exception ex)
{
MessageShow("生成圖片錯(cuò)誤!" + ex.Message);
throw;
}
graphics.Dispose();
bitmap.Dispose();
}
}

- C#實(shí)現(xiàn)圖片放大功能的按照像素放大圖像方法
- c#數(shù)字圖像處理的3種方法示例分享
- c#讀取圖像保存到數(shù)據(jù)庫(kù)中(數(shù)據(jù)庫(kù)保存圖片)
- C#灰度化圖像的實(shí)例代碼
- 解析C#彩色圖像灰度化算法的實(shí)現(xiàn)代碼詳解
- 基于c#圖像灰度化、灰度反轉(zhuǎn)、二值化的實(shí)現(xiàn)方法詳解
- C#實(shí)現(xiàn)網(wǎng)頁(yè)截圖功能
- c#實(shí)現(xiàn)winform屏幕截圖并保存的示例
- 解決C#全屏幕截圖的實(shí)現(xiàn)方法
- 解決C# 截取當(dāng)前程序窗口指定位置截圖的實(shí)現(xiàn)方法
- C#截圖程序類似騰訊QQ截圖實(shí)現(xiàn)代碼
- C#實(shí)現(xiàn)類似qq的屏幕截圖程序
- c#圖像截取實(shí)例
相關(guān)文章
ASP.Net刷新頁(yè)面后自動(dòng)滾動(dòng)到原來位置方法匯總
本文給大家匯總了3種ASP.Net實(shí)現(xiàn)的刷新頁(yè)面后自動(dòng)滾動(dòng)到原來位置方法,十分的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下。2015-06-06web用戶控件調(diào)用.aspx頁(yè)面里的方法
今天在一QQ技術(shù)群有朋友問: 他在web用戶控件中(.ascx)中放了一個(gè)dropdownlist控件,一個(gè)textbox控件和一個(gè)button控件。2009-04-04ASP.NET登錄注冊(cè)頁(yè)面實(shí)現(xiàn)
這篇文章主要介紹了ASP.NET登錄注冊(cè)頁(yè)面如何實(shí)現(xiàn),感興趣的小伙伴們可以參考一下2015-10-10Asp.net中安全退出時(shí)清空Session或Cookie的實(shí)例代碼
網(wǎng)站中點(diǎn)擊退出,如果僅僅是重定向到登錄/出頁(yè)面,此時(shí)在瀏覽器地址欄中輸入登錄后的某個(gè)頁(yè)面地址如主頁(yè),你會(huì)發(fā)現(xiàn)不用登錄就能訪問,這種退出并不安全了,下面通過本文給大家介紹安全退出時(shí)清空Session或Cookie的實(shí)例代碼2016-11-11DataGridView中綁定DataTable數(shù)據(jù)及相關(guān)操作實(shí)現(xiàn)代碼
DataGridView中綁定DataTable數(shù)據(jù)及相關(guān)操作2010-02-02Asp.Net Core輕松學(xué)習(xí)系列之配置文件
這篇文章主要給大家介紹了關(guān)于Asp.Net Core輕松學(xué)習(xí)系列之配置文件的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-11-11