请问一下,怎么样用C++ Builder6.0实现图片旋转90度和180度.
[此贴子已经被作者于2007-7-18 0:12:26编辑过]
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Graphics::TBitmap *bufferbitmap = new Graphics::TBitmap();
bufferbitmap->Width = Image1->Height;
bufferbitmap->Height = Image1->Width;
static TRect sourcepix,destpix, fullbufferimage, fulldestimage;
fullbufferimage.left = 0;
fullbufferimage.Top = bufferbitmap->Height;
fullbufferimage.Right = bufferbitmap->Width;
fullbufferimage.Bottom = 0;
for( int y=0; y < Image1->Height; ++y)
{
for( int x =0; x < Image1->Width; ++x)
{
sourcepix.Left = x;
sourcepix.Top = y+1;
sourcepix.Right = x+1;
sourcepix.Bottom = y;
destpix.Left = y;
destpix.Top = bufferbitmap->Height - x;
destpix.Right = y + 1;
destpix.Bottom = bufferbitmap->Height - x -1;
bufferbitmap->Canvas->CopyRect(destpix,Image1->Canvas,sourcepix);
}
}
Image1->Width = bufferbitmap->Width;
Image1->Height = bufferbitmap->Height;
Image1->Picture->Bitmap->Width = bufferbitmap->Width;
Image1->Picture->Bitmap->Height = bufferbitmap->Height;
Image1->Canvas->CopyRect(fullbufferimage,bufferbitmap->Canvas,fullbufferimage);
}
//---------------------------------------------------------------------------