高分求ImagXpress控件或其它可以快速旋转图像的代码

laishishenghust 2003-09-30 05:19:11
高分求ImagXpress控件或其它可以快速旋转图像的代码
...全文
71 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
54783szg 2003-10-10
  • 打赏
  • 举报
回复
头文件如下:
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TImage *Image1;
TButton *Button1;
TButton *Button2;
TButton *Button3;
TButton *Button4;
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
void __fastcall Button3Click(TObject *Sender);
void __fastcall Button4Click(TObject *Sender);
private: // User declarations
Graphics::TBitmap* bitmap1;
Graphics::TBitmap* bitmap2;
Byte *ptr;
Byte *newscanline;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

unit1.cpp文件如下:
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
bitmap1 = new Graphics::TBitmap;
bitmap2 = new Graphics::TBitmap;
try{
bitmap1->LoadFromFile("Factory.bmp");
bitmap1->PixelFormat = pf8bit;
bitmap2->PixelFormat = pf8bit;
bitmap2->Palette = bitmap1->Palette;
}
catch(...){
ShowMessage("Could not load or alter bitmap");
};

}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
delete bitmap1;
delete bitmap2;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Image1->Canvas->FillRect(Image1->Canvas->ClipRect);
Image1->Canvas->Draw(0,0,bitmap1);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{

Image1->Canvas->FillRect(Image1->Canvas->ClipRect);
bitmap2->Height = bitmap1->Height;
bitmap2->Width = bitmap1->Width;

for (int y = 0; y < bitmap2->Height; y++){
ptr = static_cast<Byte*>(bitmap1->ScanLine[y]);
newscanline = static_cast<Byte*>(bitmap2->
ScanLine[((bitmap1->Height - 1) - y)]);

for (int x = 0; x < bitmap1->Width; x++)
{
newscanline[x] = ptr[x];
}

};

Image1->Canvas->Draw(0,0,bitmap2);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Image1->Canvas->FillRect(Image1->Canvas->ClipRect);
bitmap2->Height = bitmap1->Width;
bitmap2->Width = bitmap1->Height;

for (int y = 0; y < bitmap1->Width; y++){
newscanline = static_cast<Byte*>(bitmap2->ScanLine[y]);
for (int x = 0; x < bitmap1->Height; x++){
ptr = static_cast<Byte*>(bitmap1->ScanLine[x]);
newscanline[x] = ptr[y];
};
};

Image1->Canvas->Draw(0,0,bitmap2);

}
//---------------------------------------------------------------------------
请注意窗体上所用的控件!!!
laishishenghust 2003-10-08
  • 打赏
  • 举报
回复
各位大侠帮帮忙呀,小弟等着急用呀?
xizhouhawk 2003-10-08
  • 打赏
  • 举报
回复
你也可以自己写代码啊!
基本的图形算法,旋转运算
muta 2003-10-01
  • 打赏
  • 举报
回复
要多快速?
座標轉換
| X' | = | cosT -sinT | * | X |
| Y' | | sinT cosT | | Y |
防止破損就以反推的方式求出座標
再複製顏色
muta 2003-10-01
  • 打赏
  • 举报
回复
既然有朋友提供了delphi的源碼
小弟再提供一個BCB的

void ImgRotate()
{

Origin = Byte*[Height];
After = Byte*[Height];
for(int i = 0 ; i < Height ; i++ ) {
Origin[i] = (Byte*)Image1->Picture->Bitmap->ScanLine[i];
After[i] = (Byte*)Image2->Picture->Bitmap->ScanLine[i];
}
for( int i = 0 ; i < Height ; i++ )
for( int j = 0 ; j < Width ; j++ ) {

X=(Xp*cosas) + (Yp*sinas); // cos value & sin value of desired
Y=(Yp*cosas) - (Xp*sinas); // desired rotate degree ;

if( 0 <= X &&
X <= Width &&
0 <= Y &&
Y <= Height )
{
After[i][j*3] = Origin[Y][X*3];
After[i][j*3+1]= Origin[Y][X*3+1];
After[i][j*3+2]= Origin[Y][X*3+2];
}
else
{
After[i][j*3]=255;
After[i][j*3+1]=255;
After[i][j*3+2]=255;
}

}
Image1->Refresh() ;
Image2->Refresh() ;
}
zihan 2003-09-30
  • 打赏
  • 举报
回复
procedure RotateBitmap90Degrees(ABitmap: TBitmap);

const
BITMAP_HEADER_SIZE = SizeOf(TBitmapFileHeader) +
SizeOf(TBitmapInfoHeader);

var
{ Things that end in R are for the rotated image. }
PbmpInfoR: PBitmapInfoHeader;
bmpBuffer, bmpBufferR: PByte;
MemoryStream, MemoryStreamR: TMemoryStream;
PbmpBuffer, PbmpBufferR: PByte;
PbmpBufferRFirstScanLine, PbmpBufferColumnZero: PByte;
BytesPerPixel, BytesPerScanLine, BytesPerScanLineR: Integer;
X, Y, T: Integer;

begin
{
Don't *ever* call GetDIBSizes! It screws up your bitmap.
I'll be posting about that shortly.
}

MemoryStream := TMemoryStream.Create;

{
To do: Put in a SetSize, which will eliminate any reallocation
overhead.
}

ABitmap.SaveToStream(MemoryStream);

{
Don't need you anymore. We'll make a new one when the time comes.
}
ABitmap.Free;

bmpBuffer := MemoryStream.Memory;

{ Set PbmpInfoR to point to the source bitmap's info header. }
{ Boy, these headers are getting annoying. }
Inc( bmpBuffer, SizeOf(TBitmapFileHeader) );
PbmpInfoR := PBitmapInfoHeader(bmpBuffer);

{ Set bmpBuffer to point to the original bitmap bits. }
Inc(bmpBuffer, SizeOf(PbmpInfoR^));
{ Set the ColumnZero pointer to point to, uh, column zero. }
PbmpBufferColumnZero := bmpBuffer;

with PbmpInfoR^ do
begin
BytesPerPixel := biBitCount shr 3;
{ ScanLines are DWORD aligned. }
BytesPerScanLine := ((((biWidth * biBitCount) + 31) div 32) * SizeOf(DWORD));
BytesPerScanLineR := ((((biHeight * biBitCount) + 31) div 32) * SizeOf(DWORD));

{ The TMemoryStream that will hold the rotated bits. }
MemoryStreamR := TMemoryStream.Create;
{
Set size for rotated bitmap. Might be different from source size
due to DWORD aligning.
}
MemoryStreamR.SetSize(BITMAP_HEADER_SIZE + BytesPerScanLineR * biWidth);
end;

{ Copy the headers from the source bitmap. }
MemoryStream.Seek(0, soFromBeginning);
MemoryStreamR.CopyFrom(MemoryStream, BITMAP_HEADER_SIZE);

{ Here's the buffer we're going to rotate. }
bmpBufferR := MemoryStreamR.Memory;
{ Skip the headers, yadda yadda yadda... }
Inc(bmpBufferR, BITMAP_HEADER_SIZE);

{
Set up PbmpBufferRFirstScanLine and advance it to end of the first scan
line of bmpBufferR.
}
PbmpBufferRFirstScanLine := bmpBufferR;
Inc(PbmpBufferRFirstScanLine, (PbmpInfoR^.biHeight - 1) * BytesPerPixel);

{ Here's the meat. Loop through the pixels and rotate appropriately. }

{ Remember that DIBs have their origins opposite from DDBs. }
for Y := 1 to PbmpInfoR^.biHeight do
begin
PbmpBuffer := PbmpBufferColumnZero;
PbmpBufferR := PbmpBufferRFirstScanLine;

for X := 1 to PbmpInfoR^.biWidth do
begin
for T := 1 to BytesPerPixel do
begin
PbmpBufferR^ := PbmpBuffer^;
Inc(PbmpBufferR);
Inc(PbmpBuffer);
end;
Dec(PbmpBufferR, BytesPerPixel);
Inc(PbmpBufferR, BytesPerScanLineR);
end;

Inc(PbmpBufferColumnZero, BytesPerScanLine);
Dec(PbmpBufferRFirstScanLine, BytesPerPixel);
end;

{ Done with the source bits. }
MemoryStream.Free;

{ Now set PbmpInfoR to point to the rotated bitmap's info header. }
PbmpBufferR := MemoryStreamR.Memory;
Inc( PbmpBufferR, SizeOf(TBitmapFileHeader) );
PbmpInfoR := PBitmapInfoHeader(PbmpBufferR);

{ Swap the width and height of the rotated bitmap's info header. }
with PbmpInfoR^ do
begin
T := biHeight;
biHeight := biWidth;
biWidth := T;
end;

ABitmap := TBitmap.Create;

{ Spin back to the very beginning. }
MemoryStreamR.Seek(0, soFromBeginning);
ABitmap.LoadFromStream(MemoryStreamR);

MemoryStreamR.Free;
end;

laishishenghust 2003-09-30
  • 打赏
  • 举报
回复
忘了写邮箱
laisshust@163.com

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧