} 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("", "\"));
(编辑:焦作站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|