製作小畫家 |
尚未結案
|
poetry
一般會員 發表:15 回覆:3 積分:3 註冊:2005-08-05 發送簡訊給我 |
作了一個類似小畫家畫直線圈圈的功能列如以下
在IMAGE1的ONMOUSEDOWN程式如下
void __fastcall TForm1::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
Graphics::TBitmap *TheBitmap;
StartX=(int)X*ScaleFactor;
StartY=(int)Y*ScaleFactor;
if(Pasting_Enable)
{
Pasting=true; Masking =false;Drawing=false;
Pasting_Enable=false;
}
else if(Line_Enable||Rect_Enable||Ellipse_Enable)
{
Pasting=false; Masking=false;Drawing=true;
}
else
{
Masking=true;Pasting=false;Drawing=false;
TheBitmap=Image1->Picture->Bitmap;
TheBitmap->Canvas->Draw(0,0,OrgBitmap);
}
}
在IMAGE1的ONMOUSEUP程式如下
void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button,TShiftState Shift, int X, int Y)
{
Graphics::TBitmap *TheBitmap;
EndX=(int)X*ScaleFactor;
EndY=(int)Y*ScaleFactor;
if(Pasting)
{
TheBitmap=Image1->Picture->Bitmap;
TheBitmap->Canvas->Draw(0,0,OrgBitmap);
TheBitmap->Canvas->Draw(X-StartX,Y-StartY,PasteBitmap);
OrgBitmap->Assign(TheBitmap);
}
if(Drawing)
{
TheBitmap=Image1->Picture->Bitmap;
TheBitmap->Canvas->Draw(0,0,OrgBitmap);
TheBitmap->Canvas->Pen->Style=Pen_Style;
TheBitmap->Canvas->Pen->Width=Pen_Width;
TheBitmap->Canvas->Pen->Color=Pen_Color;
if(Line_Enable)
{
TheBitmap->Canvas->MoveTo(StartX,StartY);
TheBitmap->Canvas->LineTo(EndY,EndY);
}
else if(Rect_Enable)
{
TheBitmap->Canvas->Brush->Style=bsClear;
TheBitmap->Canvas->Rectangle(StartX,StartY,EndY,EndY);
}
else if(Ellipse_Enable)
{
TheBitmap->Canvas->Brush->Style=bsClear;
TheBitmap->Canvas->Ellipse(StartX,StartY,EndX,EndY);
}
OrgBitmap->Assign(TheBitmap);
}
Masking=false;
Pasting=false;
Drawing=false;
}
在IMAGE1的ONMOUSEMOVE程式如下
void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,int X, int Y)
{
Graphics::TBitmap *TheBitmap;
TheBitmap=Image1->Picture->Bitmap;
if(TheBitmap->Empty)
{
StatusBar1->Panels->Items[0]->Text= "X="+IntToStr(X);
StatusBar1->Panels->Items[1]->Text= "Y="+IntToStr(Y);
}
if(Masking){
TheBitmap->Canvas->Pen->Mode=pmBlack;
TheBitmap->Canvas->Pen->Width=2;
TheBitmap->Canvas->Brush->Style=bsClear;
TheBitmap->Canvas->Draw(0,0,OrgBitmap);
X=(int)X*ScaleFactor;
Y=(int)Y*ScaleFactor;
TheBitmap->Canvas->Rectangle(StartX,StartY,X,Y);
}
if(Pasting)
{
TheBitmap->Canvas->Draw(0,0,OrgBitmap);
X=(int)X*ScaleFactor;
Y=(int)Y*ScaleFactor;
TheBitmap->Canvas->Draw(X-StartX,Y-StartY,PasteBitmap);
TheBitmap->Canvas->Pen->Mode=pmBlack;
TheBitmap->Canvas->Pen->Width=2;
TheBitmap->Canvas->Brush->Style=bsClear;
TheBitmap->Canvas->Rectangle(X-StartX,Y-StartY,X-StartX+PasteBitmap->Width,Y-StartY+PasteBitmap->Height);
}
if(Drawing)
{
TheBitmap->Canvas->Draw(0,0,OrgBitmap);
X=(int)X*ScaleFactor;
Y=(int)Y*ScaleFactor;
TheBitmap->Canvas->Pen->Style=Pen_Style;
TheBitmap->Canvas->Pen->Width=Pen_Width;
TheBitmap->Canvas->Pen->Color=Pen_Color;
if(Line_Enable)
{
TheBitmap->Canvas->MoveTo(StartX,StartY);
TheBitmap->Canvas->LineTo(X,Y);
}
else if(Rect_Enable)
{
TheBitmap->Canvas->Brush->Style=bsClear;
TheBitmap->Canvas->Rectangle(StartX,StartY,X,Y);
}
else if(Ellipse_Enable)
{
TheBitmap->Canvas->Brush->Style=bsClear;
TheBitmap->Canvas->Ellipse(StartX,StartY,X,Y);
}
}
}
結果可以執行卻沒辦法畫出圖形不知道哪錯了? 發表人 - poetry 於 2005/10/27 00:09:31
|
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
poetry
一般會員 發表:15 回覆:3 積分:3 註冊:2005-08-05 發送簡訊給我 |
|
RedSnow
版主 發表:79 回覆:1322 積分:845 註冊:2003-12-15 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |