【BCB】【問題】關於顯示圖片中某個區域 |
尚未結案
|
Phil999
一般會員 發表:1 回覆:1 積分:0 註冊:2004-12-31 發送簡訊給我 |
如果我今天有一個圖片在Image1,要怎麼把Image1中的某個區域
顯示在大小固定的Image2中,並且調整大小符合Image2 ?
我原本是這樣寫的:
//---------------------------------------------------------- Image1->Picture->LoadFromFile(PFile); imgWidth=Image1->Width/3;
imgHeight=Image1->Height/4; Image2->Canvas->CopyRect(Rect(0,0,imgWidth,imgHeight),
Image1->Canvas,Rect(imgWidth,imgHeight,imgWidth*2,imgHeight)); //----------------------------------------------------------
我的Image2->Stretch有設成True,不過顯示出來的圖片比例還是
和原圖一樣,所以會有圖超出範圍或留下空白的情況,請問要用
什麼方法才可以做到那種效果?
|
RaynorPao
版主 發表:139 回覆:3622 積分:7025 註冊:2002-08-12 發送簡訊給我 |
引言: 如果我今天有一個圖片在Image1,要怎麼把Image1中的某個區域 顯示在大小固定的Image2中,並且調整大小符合Image2 ? 我原本是這樣寫的: //---------------------------------------------------------- Image1->Picture->LoadFromFile(PFile); imgWidth=Image1->Width/3; imgHeight=Image1->Height/4; Image2->Canvas->CopyRect(Rect(0,0,imgWidth,imgHeight), Image1->Canvas,Rect(imgWidth,imgHeight,imgWidth*2,imgHeight)); //---------------------------------------------------------- 我的Image2->Stretch有設成True,不過顯示出來的圖片比例還是 和原圖一樣,所以會有圖超出範圍或留下空白的情況,請問要用 什麼方法才可以做到那種效果?Phil999 你好: 先試試看改成以下這個樣子,是否可行? < class="code"> Image2->Canvas->CopyRect(Rect(0, 0, imgWidth, imgHeight), Image1->Canvas, Image2->ClientRect); -- Enjoy Researching & Developing --
------
-- 若您已經得到滿意的答覆,請適時結案!! -- -- 欲知前世因,今生受者是;欲知來世果,今生做者是 -- -- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 -- |
Phil999
一般會員 發表:1 回覆:1 積分:0 註冊:2004-12-31 發送簡訊給我 |
|
KENI_LIN
中階會員 發表:86 回覆:267 積分:90 註冊:2004-05-31 發送簡訊給我 |
我是這樣想的,請參考以下程式:
void __fastcall TForm1::Button2Click(TObject *Sender)
{
int xx,yy;
int x1,x2,y1,y2;
int extd=6;
ShowRec();//顯示Image2座標矩形框
//copy image to image2-------------------------------------------------------
x1=xleft;
x2=xright;
y1=yup;
y2=ydown;
xx = x2-x1+1;
yy = y2-y1+1; for(int i=0; i<(xx-1+2*extd); i++)
{
for(int j=0; j<(yy-1+2*extd); j++)
{
Image2->Canvas->Pixels[i][j] = Image1->Canvas->Pixels[i+x1-extd][j+y1-extd];
Image2->Width=xx-1+2*extd;
Image2->Height=yy-1+2*extd;
Image2->Visible = true;
};
};
}
//--------------------------------------------------------------------------
//顯示座標矩形框--------------------------------------------------------------
void __fastcall TForm1::ShowRec()
{
int xleft,xright,yup,ydown,retake;
xleft=100;
xright=200;
yup=100;
ydown=200;
retake = Image1->Canvas->Pen->Mode;
Image1->Canvas->Pen->Mode = pmNotXor;
Image1->Canvas->Pen->Style = psDash;
Image1->Canvas->Brush->Style = bsClear;
Image1->Canvas->Rectangle(xleft,yup,xright,ydown); //cx = (xright-xleft)/2;
//cy = (ydown-yup)/2;
} 座標可以從xleft,xright,yup,ydown來修改,至於大小可以從extd去調整,你可以試試看! 還有我預視時發現
------
Keni Lin |
fffhghgjh
一般會員 發表:2 回覆:33 積分:17 註冊:2004-12-23 發送簡訊給我 |
Graphics::TBitmap *bufferbmp = new Graphics::TBitmap; TMemoryStream *pms = new TMemoryStream(); bufferbmp->Width=imgWidth; bufferbmp->Height=imgHeigth; bufferbmp->Canvas->CopyRect(Rect(0,0,imgWidth,imgHeight), Image1->Canvas,Rect(imgWidth,imgHeight,imgWidth*2,imgHeight)); bufferbmp->SaveToStream(pms); pms->Position=0; Image2->Picture->Bitmap->LoadFromStream(pms); delete pms; delete bufferbmp;這樣在Image2的stretch設成true 也會符合Image2的大小了 發表人 - fffhghgjh 於 2005/01/06 14:08:37 |
bug
一般會員 發表:0 回覆:5 積分:1 註冊:2004-10-22 發送簡訊給我 |
|
bug
一般會員 發表:0 回覆:5 積分:1 註冊:2004-10-22 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |