如何使用Image控件进行图像(bmp格式)旋转?速度要快才好!(100分)

  • 主题发起人 主题发起人 绿光
  • 开始时间 开始时间
绿

绿光

Unregistered / Unconfirmed
GUEST, unregistred user!
如何使用Image控件进行图像(bmp格式)旋转?速度要快才好!
对不起各位,本人的积分很少,所以只能支付100分,谢谢
 
补充一下,旋转90度就可以
 
从delphi转换过来的,具体参考
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1600015
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1153142
//旋转方向
typedef enum RotateDirection
{
RD_CLOCKWISE = 1,
RD_ANTI_CLOCKWISE = 2
}ROTATEDIRECTION;
long __fastcall GetPixelSize(Graphics::TBitmap *aBitmap)
{
long nBitCount, nMultiplier;
long BitsPerByte = 8;
switch (aBitmap->PixelFormat)
{
case pfDevice:
nBitCount = GetDeviceCaps(aBitmap->Canvas->Handle, BITSPIXEL);
nMultiplier = nBitCount / BitsPerByte;
if (nBitCount % BitsPerByte)
{
nMultiplier ++;
}
break;
case pf1bit:
nMultiplier = 1;
break;
case pf4bit:
nMultiplier = 1;
break;
case pf8bit:
nMultiplier = 1;
break;
case pf15bit:
nMultiplier = 2;
break;
case pf16bit:
nMultiplier = 2;
break;
case pf24bit:
nMultiplier = 3;
break;
case pf32bit:
nMultiplier = 4;
break;
default :
//ShowMessage("Unknow bitmap pileformat/n");
nMultiplier = -1;
}
return (nMultiplier);
}
//---------------------------------------------------------------------------
void __fastcall ImageRotate90(Graphics::TBitmap *aBitmap,ROTATEDIRECTION RDir)
{
long nIdx,nOfs,x,y,i,nMultiplier;
long nMemWidth, nMemHeight, nMemSize,nScanLineSize;
char *aScnLnBuffer;
PByteArray aScanLine;
if (!aBitmap)
{
return;
}
nMultiplier = GetPixelSize(aBitmap);
if (nMultiplier < 3)
{
aBitmap->PixelFormat = pf24bit;
nMultiplier = 3;
}
nMemWidth = aBitmap->Height;
nMemHeight = aBitmap->Width;
nMemSize = nMemWidth * nMemHeight * nMultiplier;
aScnLnBuffer = (char *)malloc(sizeof(char *) * nMemSize);
try
{
nScanLineSize = aBitmap->Width * nMultiplier;
aScanLine = (PByteArray)malloc(nScanLineSize);
try
{
for (y = 0;y < aBitmap->Height;y ++)
{
Move(aBitmap->ScanLine[y],aScanLine,nScanLineSize);
for (x = 0;x < aBitmap->Width;x ++)
{
if (RDir == RD_ANTI_CLOCKWISE)
{
nIdx = ((aBitmap->Width - 1) - x) * nMultiplier;
nOfs = (x * nMemWidth * nMultiplier) + (y * nMultiplier);
}
else
{
nIdx = x * nMultiplier;
nOfs = (x * nMemWidth * nMultiplier) + (((aBitmap->Height - 1) - y) * nMultiplier);
}
for (i = 0;i < nMultiplier;i ++)
{
(Byte)aScnLnBuffer[nOfs + i] = aScanLine[nIdx + i];
}
}
}
aBitmap->Height = nMemHeight;
aBitmap->Width = nMemWidth;
for (y = 0;y < nMemHeight;y ++)
{
nOfs = y * nMemWidth * nMultiplier;
Move(&amp;(aScnLnBuffer[nOfs]),aBitmap->ScanLine[y],nMemWidth * nMultiplier);
}
}
catch (...)
{
//ShowMessage("error/n");
}
}
catch (...)
{
//ShowMessage("error error/n");
}
free(aScanLine);
free(aScnLnBuffer);
}
 
我觉的用PHOTOSHOP处理一下不是更好,这样就少了很多的麻烦,你可以按你的意愿任意设计你的图形不是跟好吗?
 
看看大侠的 Keylife: http://www.delphibbs.com/keylife/iblog_show.asp?xid=212
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部