chagigi
一般會員
發表:5 回覆:1 積分:1 註冊:2003-11-17
發送簡訊給我
|
想問一下...如何取得Image2的大小放在Edit2中.以方便跟Image1比較壓縮後ㄉ大小..我Edit1是用FileListBox1選檔時讀檔名.但是Edit2就是沒辦法弄出檔案大小.以下是我ㄉ程式....
/////////////////////////////////////////////////////////////////////
//--------------------------------------------------------------------------- #include
#pragma hdrstop
#include
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall Compress(void);
void __fastcall TForm1::FileListBox1Change(TObject *Sender)
{ int w,h;
float f;
// check if jpeg file
if(ExtractFileExt(FileListBox1->FileName).UpperCase()==".JPG")
{ // load jpeg process
TJPEGImage *JImage;
JImage = new TJPEGImage;
JImage->LoadFromFile(FileListBox1->FileName);
Image1->Picture->Bitmap->Assign(JImage); // maintain aspect ratio (Image1's Stretch must be true)
w = JImage->Width;
h = JImage->Height;
f = (float)h / w;
w = ScrollBox1->Width-4;
h = f * w;
if(h>(ScrollBox1->Height-4))
{ h = ScrollBox1->Height-4;
w = h/f;
}
Image1->SetBounds(0,0,w,h); Image2->Picture->Bitmap->Assign(JImage);
w = JImage->Width;
h = JImage->Height;
f = (float)h / w;
w = ScrollBox2->Width-4;
h = f * w;
if(h>(ScrollBox2->Height-4))
{ h = ScrollBox2->Height-4;
w = h/f;
}
Image2->SetBounds(0,0,w,h); delete JImage;
// display current file name
Caption = FileListBox1->FileName; //read file size
AnsiString FName;
if(ExtractFileExt(FileListBox1->FileName).UpperCase()==".JPG")
FName=FileListBox1->FileName;
HANDLE fo = ::CreateFile(FName.c_str(),
GENERIC_READ | GENERIC_WRITE,
0,NULL,
OPEN_EXISTING,
FILE_FLAG_WRITE_THROUGH,
NULL); BY_HANDLE_FILE_INFORMATION fd;
if(::GetFileInformationByHandle(fo, &fd))
{
Edit1->Text=("" + AnsiString((int)fd.nFileSizeLow)/1000 + " KByte");
}
}
//read file size END
}
//--------------------------------------------------------------------------- void __fastcall TForm1::ScrollBar1Change(TObject *Sender)
{
int w,h;
float f; TJPEGImage *JpegBuf = new TJPEGImage();
JpegBuf->Assign(Image1->Picture->Bitmap);
JpegBuf->CompressionQuality = ScrollBar1->Position;
QEdit->Text=ScrollBar1->Position;
JpegBuf->SaveToFile("c:\\123.jpg"); JpegBuf->LoadFromFile("c:\\123.jpg");
Image2->Picture->Bitmap->Assign(JpegBuf); w = JpegBuf->Width;
h = JpegBuf->Height;
f = (float)h / w;
w = ScrollBox2->Width-4;
h = f * w;
if(h>(ScrollBox2->Height-4))
{ h = ScrollBox2->Height-4;
w = h/f;
}
Image2->SetBounds(0,0,w,h); //Image2->Picture->Assign(JpegBuf);
delete JpegBuf;
}
//--------------------------------------------------------------------------- void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
TJPEGImage *JImage;
if(SaveDialog1->Execute())
{
JImage = new TJPEGImage;
// copy bitmap into TJpegImage form TImage's Bitmap
JImage->Assign(Image2->Picture->Bitmap);
// save to file process
JImage->SaveToFile(SaveDialog1->FileName + ".jpg");
// delete TJpegImage
delete JImage;
}
}
//---------------------------------------------------------------------------
|
dllee
站務副站長
發表:321 回覆:2519 積分:1711 註冊:2002-04-15
發送簡訊給我
|
在程式中看不到 Edit2 呀?!
其實要取得檔案的大小,可以使用 TFileStream
利用 TFileStream 開檔,用 Size 屬性就可以取得檔案大小,不一定需要用到 Windows API。 沒空更新的網頁...
http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://dllee.adsldns.org 介紹Shells,LiteStep,GeoShell....
------ http://www.ViewMove.com
|