0
我正试图找到最简单的方法来旋转并在其中心显示一个TBitmap
所需的任何给定角度。 TBitmap
是正方形的,只要旋转的位图的中心点保持不变,任何可能发生的剪切都不重要。图像非常小,只有50 x 50像素左右,所以速度不是问题。这里是我到目前为止的代码,它将TBitmap
旋转到90度,这很简单,任何角度都不那么重要。在其中心旋转一个正方形TBitmap
std::auto_ptr<Graphics::TBitmap> bitmap1(new Graphics::TBitmap);
std::auto_ptr<Graphics::TBitmap> bitmap2(new Graphics::TBitmap);
bitmap1->LoadFromFile("c:/myimage.bmp");
bitmap1->Transparent = true;
bitmap1->TransparentColor = bitmap1->Canvas->Pixels[50][50];
bitmap2->Width=bitmap1->Height;
bitmap2->Height=bitmap1->Width;
double x1 = 0.0;
double y1 = 0.0;
for (int x = 0;x < bitmap1->Width; x++)
{
for(int y = 0;y < bitmap1->Height;y++)
{
x1 = std::cos(45.0) * x - std::sin(45.0) * y;
y1 = sin(45.0) * x + cos(45.0) * y;
bitmap2->Canvas->Pixels[x1][y1] =
bitmap1->Canvas->Pixels[x][y];
}
}
Form1->Canvas->Draw(500, 200, bitmap2.get());
请参阅修改的代码...这允许旋转,但副本会创建模糊的图像,旋转点位于左上角。
@Raw N阱的问题是存在的......你的意思是我的编辑发布以包括答案? – Jim
您想要实施[旋转矩阵](https://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/2drota.htm)。大多数图形软件包都有一个矩阵变换库。 – selbie
https://stackoverflow.com/questions/10633400/rotate-bitmap-by-real-angle – selbie