ASP.NET 2.0,C\#-이미지 필터 처리
7820 단어 ASP.NET 2.0C\#---이미지 필터 처리
public partial class WebForm4 : System.Web.UI.Page { // 원본 그림 경로 private string path; private System.Drawing.Bitmap bitmap; private System.Drawing.Graphics graphics; string Message = "
bitmap = new Bitmap(path); graphics = Graphics.FromImage(bitmap); graphics.DrawString(log,new Font("송 체",16),System.Drawing.Brohes.GreenYellow,new Pointf(bitmap.Width/2-(log.Length)*5,bitmap.Height/2); try { bitmap.Save(Server.MapPath("./_Log.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg); Message Show("워 터 마크 그림 이 생 성 되 었 습 니 다.경 로 는"[email protected]("./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); Message Show("그림 이 생 성 되 었 습 니 다.경 로 는"[email protected]("./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); Message Show("그림 이 생 성 되 었 습 니 다.경 로 는"[email protected]("./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); Message Show("그림 이 생 성 되 었 습 니 다.경 로 는"[email protected]("./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); Message Show("그림 이 생 성 되 었 습 니 다.경 로 는"[email protected]("./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); Message Show("그림 이 생 성 되 었 습 니 다.경 로 는"[email protected]("./Elongate.jpg").Replace("\\", " \\\\ "));
} catch (Exception ex) { MessageShow("그림 생 성 오류!"+ex.Message); throw; } graphics.Dispose(); bitmap.Dispose(); } }