-1

The main task is to make roulette wheel image spinning on a given angle. It does not matter whether it is a plane, picture box or something else, the main thing is that it is possible to turn at a clearly defined angle

Current variant rotates it only by 90 degrees

pictureBox1->Image->RotateFlip(RotateFlipType::Rotate90FlipNone);
pictureBox1->Refresh();
wohlstad
  • 12,661
  • 10
  • 26
  • 39
L0mTiCk
  • 31
  • 2
  • Just guessing, but isn't there a way to rotate-transform the picture? Edit: [`RotateTransform`](https://stackoverflow.com/a/26455088/7582247) in a C# answer. Perhaps you can depickle that. – Ted Lyngmo Mar 13 '23 at 14:35
  • as i know, it's for graphics, but i don't know how to convert graphics to image then – L0mTiCk Mar 13 '23 at 14:38
  • This question is in C#, but I belive a translation to c++/cli (which you seem to use) should be quite straightforward: https://stackoverflow.com/questions/2163829/how-do-i-rotate-a-picture-in-winforms. – wohlstad Mar 13 '23 at 14:38
  • @L0mTiCk Did you look at the answer? It makes a BMP out of the `PictureBox.Image`, then `RotateTransform`s that. – Ted Lyngmo Mar 13 '23 at 14:40
  • yes, but there are lots of errors, i tried to translate to c++ but I didn't have enough knowledge – L0mTiCk Mar 13 '23 at 14:51
  • I think you should be looking for C++/CLI solutions. Not C++ solutions as you are apparently programming in C++/CLI, not C++. – Ted Lyngmo Mar 13 '23 at 15:18
  • omg, i did i, but there's 1 problem, that after a couple of rotations image becomes blurry – L0mTiCk Mar 13 '23 at 15:30
  • @L0mTiCk You need to keep the original image and use that for each rotation. Every rotation introduces noise, just like if you kept copying a tape of music in many generations, so always use the original, copy it and then rotate the copy with the target angle. – Ted Lyngmo Mar 13 '23 at 19:37

1 Answers1

-1

Answer (the original code in C#: Rotate picture in Winforms) + it's useless at this moment because of bluring and memory usage increasing:

    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;
    }

But there's 1 problem, after a couple of rotations image becomes blurry.

L0mTiCk
  • 31
  • 2
  • 3
    Don't rotate the same image repeatedly, keep the original around so you can always create a fresh new rotated copy. Attribution is required here btw. – Hans Passant Mar 13 '23 at 15:40
  • honestly, I don't quite understand what you wanted to say, but the current method with multiple rotations also greatly increases the memory used – L0mTiCk Mar 14 '23 at 16:21
  • You have to dispose the image to avoid out-of-control memory usage. if (pictureBox1->Image != nullptr) delete pictureBox1->Image; pictureBox1->Image = RotateImage(...); – Hans Passant Mar 14 '23 at 16:26