線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1124
推到 Plurk!
推到 Facebook!

問~有關影像檔案大小ㄉ問題

尚未結案
chagigi
一般會員


發表:5
回覆:1
積分:1
註冊:2003-11-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-11-25 01:12:38 IP:218.164.xxx.xxx 未訂閱
想問一下...如何取得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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-11-25 09:42:56 IP:211.76.xxx.xxx 未訂閱
在程式中看不到 Edit2 呀?! 其實要取得檔案的大小,可以使用 TFileStream 利用 TFileStream 開檔,用 Size 屬性就可以取得檔案大小,不一定需要用到 Windows API。    沒空更新的網頁... http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://dllee.adsldns.org 介紹Shells,LiteStep,GeoShell....
------
http://www.ViewMove.com
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-11-25 13:31:52 IP:140.135.xxx.xxx 未訂閱
chagigi您好: 插一下花,您可以參考下面聯結讓您的程式碼更容易閱讀喔 < href="http://delphi.ktop.com.tw/topic.php?TOPIC_ID=40594">http://delphi.ktop.com.tw/topic.php?TOPIC_ID=40594 順心
系統時間:2024-05-06 13:40:06
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!