我構建了這個示例以快速將影像旋轉 90 度,但我總是在側面截取影像。經過多次測驗,不幸的是我仍然不明白問題的原因。
void rotate()
{
Graphics::TBitmap *SrcBitmap = new Graphics::TBitmap;
Graphics::TBitmap *DestBitmap = new Graphics::TBitmap;
SrcBitmap->LoadFromFile("Crayon.bmp");
DestBitmap->Width=SrcBitmap->Width;
DestBitmap->Height=SrcBitmap->Height;
SetGraphicsMode(DestBitmap->Canvas->Handle, GM_ADVANCED);
double myangle = (double)(90.0 / 180.0) * 3.1415926;
int x0=SrcBitmap->Width/2;
int y0=SrcBitmap->Height/2;
double cx=x0 - cos(myangle)*x0 sin(myangle)*y0;
double cy=y0 - cos(myangle)*y0 - sin(myangle)*x0;
xForm.eM11 = (FLOAT) cos(myangle);
xForm.eM12 = (FLOAT) sin(myangle);
xForm.eM21 = (FLOAT) -sin(myangle);
xForm.eM22 = (FLOAT) cos(myangle);
xForm.eDx = (FLOAT) cx;
xForm.eDy = (FLOAT) cy;
SetWorldTransform(DestBitmap->Canvas->Handle, &xForm);
BitBlt(DestBitmap->Canvas->Handle,
0,
0,
SrcBitmap->Width,
SrcBitmap->Height,
SrcBitmap->Canvas->Handle,
0,
0,
SRCCOPY);
DestBitmap->SaveToFile("Crayon2.bmp");
delete DestBitmap;
delete SrcBitmap;
}
uj5u.com熱心網友回復:
如果旋轉整個影像,則應翻轉目標影像的寬度和高度:
DestBitmap->Width = SrcBitmap->Height;
DestBitmap->Height = SrcBitmap->Width;
變換例程根據原始寬度/高度將影像居中。我們要調整 x/y 位置以將起點推到左/上BitBlt
int offset = (SrcBitmap->Width - SrcBitmap->Height) / 2;
BitBlt(DestBitmap->Canvas->Handle, offset, offset, SrcBitmap->Width, SrcBitmap->Height,
SrcBitmap->Canvas->Handle, 0, 0, SRCCOPY);
uj5u.com熱心網友回復:
有一次我遇到了類似的問題。我想圍繞一個共同的旋轉點旋轉兩個影像。但是我不能用標準函式來做,因為它不允許旋轉點分散到中心。盡管如此,我當時已經對標準功能做了筆記。也許他們會幫助你。我記得目標影像的大小正確很重要!如果縱向影像變成橫向影像,影像變得更寬,因此 BitBlt 函式還必須指定目標影像的大小。
這是我對標準功能的說明。填充 xForm 引數對我來說與您的代碼片段中的不太一樣。

這就是我用來圍繞任何中心旋轉的功能。

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/314209.html
標籤:C 视窗 时间:2019-05-06 标签:c builder
上一篇:PYODBC在連接字串中傳遞變數
