全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:919
推到 Plurk!
推到 Facebook!

編輯 JPEG 的問題

尚未結案
st
一般會員


發表:11
回覆:21
積分:11
註冊:2004-07-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-07-09 16:49:29 IP:211.22.xxx.xxx 未訂閱
我想自己寫一個像 photoed 般可以隨意剪貼 圖檔的某一區段的程式(請參考詳圖)    基本上我已經做到可以載入 JPEG 及壓縮合存檔了 但是我不知要如何為做一個可動態張縮 的"橡皮筋"來定義要存出的區塊    範例如下:    //---------------------------------------------------------------------------    void __fastcall TForm1::Button3Click(TObject *Sender) {   TJPEGImage *jpg = new TJPEGImage();   Graphics::TBitmap *bmp1 = new Graphics::TBitmap();   bmp2 = new Graphics::TBitmap();      try   {     jpg->LoadFromFile("D:\\MyPrograms\\CPP\\EZShow\\Maastricht\\Maastricht001.jpg");     bmp1->Assign(jpg);        //Change Size     bmp2->Width=500;     bmp2->Height=500;        int x1,y1,x2,y2,x0,y0,dx,dy,x,y;        x1=bmp1->Width;     y1=bmp1->Height;     x2=bmp2->Width;     y2=bmp2->Height;     dx=0;     x0=0;     for (x=0 ; x<=bmp2->Width-1 ; x++)     {         dy=0;         y0=0;         dx=dx+x1;            while (dx>=x2)               {                 x0++;                 dx=dx-x2;               }            for (y=0 ; y<=bmp2->Height-1 ; y++)             {               dy=dy+y1;               while (dy>=y2)                     {                      y0++;                      dy=dy-y2;                     }               bmp2->Canvas->Pixels[x][y]=bmp1->Canvas->Pixels[x0][y0];             }        }        //jpg->Assign(bmp2);     //jpg->SaveToFile("D:\\MyPrograms\\CPP\\EZShow\\Test1.jpg");     Image1->Picture->Assign(bmp2);          }   catch (...)   {     ShowMessage("Could not load or alter JPEG Files");   }      delete jpg;   delete bmp1;   //delete bmp2;    } //---------------------------------------------------------------------------    void __fastcall TForm1::PaintBox1MouseMove(TObject *Sender,       TShiftState Shift, int X, int Y) {   //if(Drawing)   //{     PaintBox1->Canvas->CopyRect(PaintBox1->ClientRect, Image1->Canvas, Image1->ClientRect);     PaintBox1->Canvas->Brush->Style=bsClear;     PaintBox1->Canvas->Pen->Style=psDot;     PaintBox1->Canvas->Pen->Color=clBlack;     PaintBox1->Canvas->MoveTo(X, 0);     PaintBox1->Canvas->LineTo(X, PaintBox1->Height);     PaintBox1->Canvas->MoveTo(0, Y);     PaintBox1->Canvas->LineTo(PaintBox1->Width, Y);   //} } //---------------------------------------------------------------------------    void __fastcall TForm1::PaintBox1MouseDown(TObject *Sender,       TMouseButton Button, TShiftState Shift, int X, int Y) {   if (!Drawing)   {     Image1->Picture->Assign(bmp2);   }      Drawing = true;   rRect.Left=X;   rRect.Top=Y; } //---------------------------------------------------------------------------    void __fastcall TForm1::PaintBox1MouseUp(TObject *Sender,       TMouseButton Button, TShiftState Shift, int X, int Y) {   rRect.Right=X;   rRect.Bottom=Y;      Image1->Canvas->Brush->Style=bsClear;   //Image1->Canvas->FrameRect(rRect);   Image1->Canvas->Rectangle(rRect.Left,rRect.Top,rRect.Right,rRect.Bottom);   Drawing = false; } //---------------------------------------------------------------------------    void __fastcall TForm1::FormCreate(TObject *Sender) {   Drawing=true; } //---------------------------------------------------------------------------    
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-07-09 16:57:06 IP:203.73.xxx.xxx 未訂閱
引言: 我想自己寫一個像 photoed 般可以隨意剪貼 圖檔的某一區段的程式(請參考詳圖) 基本上我已經做到可以載入 JPEG 及壓縮合存檔了 但是我不知要如何為做一個可動態張縮 的"橡皮筋"來定義要存出的區塊 範例如下: //--------------------------------------------------------------------------- void __fastcall TForm1::Button3Click(TObject *Sender) { TJPEGImage *jpg = new TJPEGImage(); Graphics::TBitmap *bmp1 = new Graphics::TBitmap(); bmp2 = new Graphics::TBitmap(); try { jpg->LoadFromFile("D:\\MyPrograms\\CPP\\EZShow\\Maastricht\\Maastricht001.jpg"); bmp1->Assign(jpg); //Change Size bmp2->Width=500; bmp2->Height=500; int x1,y1,x2,y2,x0,y0,dx,dy,x,y; x1=bmp1->Width; y1=bmp1->Height; x2=bmp2->Width; y2=bmp2->Height; dx=0; x0=0; for (x=0 ; x<=bmp2->Width-1 ; x++) { dy=0; y0=0; dx=dx+x1; while (dx>=x2) { x0++; dx=dx-x2; } for (y=0 ; y<=bmp2->Height-1 ; y++) { dy=dy+y1; while (dy>=y2) { y0++; dy=dy-y2; } bmp2->Canvas->Pixels[x][y]=bmp1->Canvas->Pixels[x0][y0]; } } //jpg->Assign(bmp2); //jpg->SaveToFile("D:\\MyPrograms\\CPP\\EZShow\\Test1.jpg"); Image1->Picture->Assign(bmp2); } catch (...) { ShowMessage("Could not load or alter JPEG Files"); } delete jpg; delete bmp1; //delete bmp2; } //--------------------------------------------------------------------------- void __fastcall TForm1::PaintBox1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { //if(Drawing) //{ PaintBox1->Canvas->CopyRect(PaintBox1->ClientRect, Image1->Canvas, Image1->ClientRect); PaintBox1->Canvas->Brush->Style=bsClear; PaintBox1->Canvas->Pen->Style=psDot; PaintBox1->Canvas->Pen->Color=clBlack; PaintBox1->Canvas->MoveTo(X, 0); PaintBox1->Canvas->LineTo(X, PaintBox1->Height); PaintBox1->Canvas->MoveTo(0, Y); PaintBox1->Canvas->LineTo(PaintBox1->Width, Y); //} } //--------------------------------------------------------------------------- void __fastcall TForm1::PaintBox1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (!Drawing) { Image1->Picture->Assign(bmp2); } Drawing = true; rRect.Left=X; rRect.Top=Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::PaintBox1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { rRect.Right=X; rRect.Bottom=Y; Image1->Canvas->Brush->Style=bsClear; //Image1->Canvas->FrameRect(rRect); Image1->Canvas->Rectangle(rRect.Left,rRect.Top,rRect.Right,rRect.Bottom); Drawing = false; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { Drawing=true; } //---------------------------------------------------------------------------
st 你好: 你講的功能,是不是類似這個樣子? src="http://delphi.ktop.com.tw/loadfile.php?TOPICID=10003806&CC=223734"> -- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
系統時間:2024-05-15 6:26:38
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!