zoukankan      html  css  js  c++  java
  • c# pictureBox 360度旋转

    public static Bitmap RotateImage(Image image, float angle)
    {
    if (image == null)
    throw new ArgumentNullException("image");
    float dx = image.Width / 2.0f;
    float dy = image.Height / 2.0f;

    Bitmap rotatedBmp = new Bitmap(image.Width, image.Height);
    rotatedBmp.SetResolution(image.HorizontalResolution, image.VerticalResolution);
    Graphics g = Graphics.FromImage(rotatedBmp);
    g.TranslateTransform(dx, dy);
    g.RotateTransform(angle);
    g.TranslateTransform(-dx, -dy);
    g.DrawImage(image, new PointF(0, 0));
    return rotatedBmp;
    }

    void tm_Elapsed(object sender, EventArgs e)
    {
    if (isStart)
    {
    angle += 5;
    if (angle >= 359) angle = 0;
    RotateImage(pic1, Properties.Resources._1, angle);
    }
    }

    private void RotateImage(PictureBox pb, Image img, float angle)
    {
    if (img == null || pb.Image == null)
    return;
    Image oldImage = pb.Image;
    pb.Image = Utilities.RotateImage(img, angle);
    if (oldImage != null)
    {
    oldImage.Dispose();
    }
    }

  • 相关阅读:
    linux 常用命令
    git 常见命令
    合并两个有序链表---python
    Code Contract for .NET
    Kruskal最小生成树算法
    逻辑-哲学
    停机问题
    逆向工程
    .net framework
    python 类库
  • 原文地址:https://www.cnblogs.com/94cool/p/2802123.html
Copyright © 2011-2022 走看看