码迷,mamicode.com
首页 > 其他好文 > 详细

图片缩放/旋转/平移

时间:2015-01-20 17:32:22      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

Bitmap bmp1 = new Bitmap(picOri.Image);//创建图形对象
            Bitmap bmp2 = new Bitmap(picOri.Image);
            using (Graphics g = picThumb.CreateGraphics())//创建画板
            {
               // g.Clear(picThumb.BackColor);//清空画板 
                g.ScaleTransform(0.5F, 0.5F, System.Drawing.Drawing2D.MatrixOrder.Append);//缩放
          /*缩放*/

int width = Convert.ToInt32(0.5*image.Width);//缩放宽度
int height = Convert.ToInt32(0.5 * image.Height);//缩放高度
graphics.DrawImage(image, this.ClientSize.Width/2, this.ClientSize.Height/2, width, height);//绘制图像

          /*缩放*/
          /*旋转*/
          //g.RotateTransform(320F);//旋转

Image image = global::TEST.Properties.Resources.ChatFormBG;// Image.FromFile("11.jpg");
//获取当前窗口的中心点
Rectangle rec = new Rectangle(0, 0, this.ClientSize.Width, this.ClientSize.Height);
PointF center = new PointF(rec.Width / 2, rec.Height / 2);
float offsetX = 0;
float offsetY = 0;
offsetX = center.X = image.Width / 2;
offsetY = center.Y - image.Height / 2;
RectangleF recf = new RectangleF(offsetX, offsetY, image.Width, image.Height);
PointF centerf = new PointF(recf.X + recf.Width / 2, recf.Y + recf.Height / 2);
//实现旋转
Graphics g = this.CreateGraphics();
g.Clear(this.BackColor);
g.TranslateTransform(centerf.X, centerf.Y);
g.RotateTransform(10F);
g.TranslateTransform(-centerf.X, -centerf.Y);
//显示图像
g.DrawImage(image, new PointF(rec.Width / 4, rec.Height / 4));

/*旋转*/
          //g.TranslateTransform(10F, 10F);//平移
//重绘图像 //PictureBox g.DrawImage(bmp1, this.picThumb.ClientRectangle, 0, 0, bmp2.Width, bmp2.Height, GraphicsUnit.Pixel); } bmp1.Dispose(); bmp2.Dispose();

 

图片缩放/旋转/平移

标签:

原文地址:http://www.cnblogs.com/wjshan0808/p/4236182.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!