注册 登录
编程论坛 C++ Builder

[求助]怎么样让图片出现翻转

lzhp040424 发布于 2007-07-18 00:11, 1445 次点击
各位大虾:
请问一下,怎么样用C++ Builder6.0实现图片旋转90度和180度.

[此贴子已经被作者于2007-7-18 0:12:26编辑过]

1 回复
#2
热情依然2007-07-29 16:59

//---------------------------------------------------------------------------

#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);

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

1