当前位置: 代码迷 >> 综合 >> UI(17)——使用GDI+实现图像旋转的2种简单方法
  详细解决方案

UI(17)——使用GDI+实现图像旋转的2种简单方法

热度:27   发布时间:2023-10-01 13:35:08.0

方法一:旋转画图区,以90度旋转为例

        private void btnRotate90_Click(object sender, EventArgs e){Graphics gs = pictureBox1.CreateGraphics();string strFile = @"E:\p.jpg";Bitmap bmp = new Bitmap(strFile);gs.FillRectangle(Brushes.White, pictureBox1.ClientRectangle);Point[] destinationPoints = { new Point(ClientRectangle.Width, 0), new Point(ClientRectangle.Width, ClientRectangle.Height), new Point(0, 0) };gs.DrawImage(bmp, destinationPoints);}

方法二:旋转图像自身,以90度旋转为例

        private void btnRotate90_Click(object sender, EventArgs e){Graphics gs = pictureBox1.CreateGraphics();string strFile = @"E:\p.jpg";Image img = Image.FromFile(strFile);img.RotateFlip(RotateFlipType.Rotate90FlipNone);gs.DrawImage(img, pictureBox1.ClientRectangle);}

 

  相关解决方案