**已关闭。**此问题需要debugging details。当前不接受答案。
编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
2天前关闭。
Improve this question
通过这段代码,我旋转了一些图像,我看到在第二次旋转之后,图像立即丢失了信息。我以为问题是由于图像的居中,但事实并非如此。问题可能是什么?
void RotatePicture1(double myangle, TObject *Sender)
{
XFORM xForm;
Graphics::TBitmap *SrcBitmap = new Graphics::TBitmap;
Graphics::TBitmap *DestBitmap = new Graphics::TBitmap;
SrcBitmap->PixelFormat=pf24bit;
DestBitmap->PixelFormat=pf24bit;
TImage *MyImage = (TImage*)Sender;
SrcBitmap->Width=MyImage->Width;
SrcBitmap->Height=MyImage->Height;
DestBitmap->Width=MyImage->Width;
DestBitmap->Height=MyImage->Height;
SrcBitmap->Assign(MyImage->Picture->Bitmap);
SetGraphicsMode(DestBitmap->Canvas->Handle, GM_ADVANCED);
double fangle = (double)(myangle / 180.0) * M_PI;
int x0=SrcBitmap->Width/2;
int y0=SrcBitmap->Height/2;
double cx=x0 - cos(fangle)*x0 + sin(fangle)*y0;
double cy=y0 - cos(fangle)*y0 - sin(fangle)*x0;
xForm.eM11 = (FLOAT) cos(fangle);
xForm.eM12 = (FLOAT) sin(fangle);
xForm.eM21 = (FLOAT) -sin(fangle);
xForm.eM22 = (FLOAT) cos(fangle);
xForm.eDx = (FLOAT) cx;
xForm.eDy = (FLOAT) cy;
SetWorldTransform(DestBitmap->Canvas->Handle, &xForm);
int offset = (MyImage->Width - MyImage->Height) / 2;
BitBlt(
DestBitmap->Canvas->Handle, //A handle to the destination device context.
0, //The x-coordinate, of the upper-left corner of the destination rectangle.
0, //The y-coordinate, of the upper-left corner of the destination rectangle.
SrcBitmap->Width, //The width, of the source and destination rectangles.
SrcBitmap->Height, //The height, of the source and the destination rectangles.
SrcBitmap->Canvas->Handle, //A handle to the source device context
0, //The x-coordinate, of the upper-left corner of the source rectangle.
0, //The y-coordinate, of the upper-left corner of the source rectangle.
SRCCOPY);
MyImage->Picture->Bitmap->Assign(DestBitmap);
delete DestBitmap;
delete SrcBitmap;
}
旋转前:
旋转几圈后:
1条答案
按热度按时间pvcm50d11#
XFORM.eDx
和XFORM.eDy
不用于旋转操作。以及WinAPI rotation works fine for me。