用C++/CLI实现Winforms中的图像旋转

xesrikrc  于 2023-03-19  发布在  其他
关注(0)|答案(1)|浏览(150)

主要的任务是使轮盘赌的轮盘图像在一个给定的Angular 旋转。不管它是一个平面,图片框或其他东西,主要的是它可以在一个明确定义的Angular 旋转
当前变体仅旋转90度

pictureBox1->Image->RotateFlip(RotateFlipType::Rotate90FlipNone);
pictureBox1->Refresh();
nkkqxpd9

nkkqxpd91#

答案(C#中的原始代码:Rotate picture in Winforms)+由于模糊和内存使用量增加,因此此时无用:

private: System::Void spinButton_Click(System::Object^ sender, System::EventArgs^ e) {
        pictureBox1->Image = RotateImage(pictureBox1->Image, 15);
    }
    public: Image^ RotateImage(Image^ img, float rotationAngle)
    {
        //create an empty Bitmap image
        Image^ bmp = Image::FromFile("rouletteWheel.png");

        //turn the Bitmap into a Graphics object
        Graphics^ gfx = Graphics::FromImage(bmp);

        //now we set the rotation point to the center of our image
        gfx->TranslateTransform((float)bmp->Width / 2, (float)bmp->Height / 2);

        //now rotate the image
        gfx->RotateTransform(rotationAngle);

        gfx->TranslateTransform(-(float)bmp->Width / 2, -(float)bmp->Height / 2);

        //set the InterpolationMode to HighQualityBicubic so to ensure a high
        //quality image once it is transformed to the specified size               
        gfx->InterpolationMode = System::Drawing::Drawing2D::InterpolationMode::HighQualityBicubic;
        //now draw our new image onto the graphics object

        gfx->DrawImage(img, 0, 0);

        //dispose of our Graphics object
        gfx->~Graphics();

        //return the image
        return bmp;
    }

但有一个问题,经过几次旋转图像变得模糊.

相关问题