winform图片缩放

01.using System;

02.using System.Drawing;
03.using System.Drawing.Imaging;
04.using System.Drawing.Drawing2D;
05.using System.Text;
06.using System.Windows.Forms;
07. 
08.namespace bitmaprerote
09.{
10.public partial class suofang : Form
11.{
12.public suofang()
13.{
14.InitializeComponent();
15.}
16./// <summary>
17./// Resize图片
18./// </summary>
19./// <param name="bmp">原始Bitmap</param>
20./// <param name="newW">新的宽度</param>
21./// <param name="newH">新的高度</param>
22./// <returns>处理以后的图片</returns>
23.public static Bitmap KiResizeImage(Bitmap bmp, int newW, int newH, int Mode)
24.{
25.try
26.{
27.Bitmap map = new Bitmap(newW, newH);
28.Graphics g = Graphics.FromImage(map);
29.// 插值算法的质量
30.g.InterpolationMode = InterpolationMode.HighQualityBicubic;
31.g.DrawImage(bmp, new Rectangle(0, 0, newW, newH), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
32.g.Dispose();
33.return map;
34.}
35.catch
36.{
37.return null;
38.}
39.}
40. 
41.private void button1_Click(object sender, EventArgs e)
42.{
43.Bitmap map = new Bitmap("F:\\hj.jpg");
44.map = KiResizeImage(map, 90, 90, 20);
45.pictureBox1.Image = map;
46.}
47.}
48.}
posted @ 2014-11-08 21:44  关中秦人  阅读(398)  评论(0)    收藏  举报