zhvickie
一般會員
發表:16 回覆:41 積分:11 註冊:2003-05-11
發送簡訊給我
|
根据本期(034)电子杂志改写的
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unit1.h"
#include "math.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void TForm1::ResizeBitmap(AnsiString Src, AnsiString Dest, int x, int y, TPixelFormat ColorBit)
{
//TODO: Add your source code here
Graphics::TBitmap *abmp, *bbmp ;
double scalex, scaley ;
abmp=new Graphics::TBitmap();
bbmp=new Graphics::TBitmap();
try{
abmp->LoadFromFile(Src);
scaley= abmp->Height/ y;
scalex= abmp->Width / x;
bbmp->Width = floor(abmp->Width / scalex);
bbmp->Height = floor(abmp->Height / scaley);
bbmp->PixelFormat= ColorBit;
SetStretchBltMode(bbmp->Canvas->Handle, COLORONCOLOR);
StretchBlt(bbmp->Canvas->Handle, 0, 0, bbmp->Width, bbmp->Height,
abmp->Canvas->Handle, 0, 0, abmp->Width, abmp->Height, SRCCOPY);
bbmp->SaveToFile(Dest);
}
__finally
{
free(abmp);
free(bbmp);
}
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ResizeBitmap("c:\\2.bmp","c:\\1.bmp",200,200,pf24bit);
}
//--------------------------------------------------------------------------- 發表人 - zhvickie 於 2003/12/03 15:20:09 發表人 - zhvickie 於 2003/12/03 15:27:28
|