TImage 构件的小问题(5分)

  • 主题发起人 主题发起人 philips
  • 开始时间 开始时间
P

philips

Unregistered / Unconfirmed
GUEST, unregistred user!
下面的程序用到 2个Image 构件,有什么错误?

void __fastcall TForm1::FormCreate(TObject *Sender)
{
int i,y;

Image2->Visible = False;
Image1->Top = 0;
Image1->Left = 0;
Image1->Height = 3000;
Image2->Canvas->Brush->Style = bsClear;

for (i=1;i<Image1->Height; i++)
{
y=100*sin(i/180.0*3.1415);
Image1->Canvas->Pixels[y+300] = clRed;
}
}


void __fastcall TForm1::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
Image2->Visible = False;
Image1->Canvas->Pen->Color = clWhite;
Image1->Canvas->Rectangle(StartPt.x,StartPt.y, EndPt.x,EndPt.y);

bDrawing = True;
StartPt = TPoint(X,Y);
EndPt = StartPt;

Image1->Canvas->Pen->Mode = pmNot;
Image1->Canvas->Pen->Color = clRed;
Image1->Canvas->Brush->Style =bsClear;
Image1->Canvas->Pen->Style = psDot;
}


void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
if( bDrawing &amp;&amp; ((EndPt.x != X)||(EndPt.y != Y)) )
{
Image1->Canvas->Rectangle(StartPt.x,StartPt.y, EndPt.x,EndPt.y);
Image1->Canvas->Rectangle(StartPt.x,StartPt.y, X,Y);
EndPt.x = X;
EndPt.y = Y;
}
}


void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
int i,j;

if( bDrawing )
{
bDrawing = False;
Image1->Canvas->Rectangle(StartPt.x,StartPt.y, EndPt.x,EndPt.y);
Image1->Canvas->Pen->Mode = pmCopy;
Image1->Canvas->Pen->Color = clBlack;
Image1->Canvas->Brush->Style = bsClear;

int itop = Image1->Top;
int ileft = Image1->Left;

Image2->Height = abs(EndPt.y - StartPt.y);
Image2->Width = abs(EndPt.x - StartPt.x);
Image2->Left = (StartPt.x>EndPt.x ? EndPt.x :StartPt.x) +ileft;
Image2->Top = (StartPt.y>EndPt.y ? EndPt.y :StartPt.y) +itop;

for(i=0;i<Image2->Height;i++)
for(j=0;j<Image2->Width;j++)
{
if( Image1->Canvas->Pixels[i+ileft][j+itop]!=clRed )
Image2->Canvas->Pixels[j]=clGreen;
else
Image2->Canvas->Pixels[j]=clRed;
}

Image2->Visible = True;
}
}


void __fastcall TForm1::Image2MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
StartPt.x = X;
StartPt.y = Y;
bDraging = True;
}


void __fastcall TForm1::Image2MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
if( bDraging )
{
Image2->Left = Image2->Left +X - StartPt.x;
Image2->Top = Image2->Top + Y - StartPt.y;
Image2->Hint = "X:"+IntToStr(Image2->Left)+" Y:"+IntToStr(Image2->Top);
}
}


void __fastcall TForm1::Image2MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
bDraging = False;
}

它不能按预期的工作,请各位大侠救命!
我只有 5 分了。
 
看看以前的解答。
 
如果各位有答案,愿将一月的分数加上
 
眼看花了,不知道,嘻嘻。
 
该程序 是先在image1上画线, 当鼠标在Image1上拖动时,动态绘制巨型橡

皮线,松开鼠标后,确定了Image2的位置和大小,再将 Image2 所覆盖的

Image1区域的曲线复制到 Image2上, 然而,不能按照动态变化的 Image2 的大小

来复制 Image1 对应区域的曲线。

问题似乎是这样,我也没解决这个问题, 请大侠关注以下。
 
就是这样。
 
这个问题 据我所知 侠怪 已解决了。
 
Image2->Height = abs(EndPt.y - StartPt.y);
Image2->Width = abs(EndPt.x - StartPt.x);
需要再设置一下:
Image2->Picture->Bitmap->Height = Image2->Height;
Image2->Picture->Bitmap->Width = Image2->Width;

 
我的程序,按您的方法,运行时,出错
 
接受答案了.
 
后退
顶部