Image不能动态改变width,heigth的情况??改了也无法在增大后的区域绘图!!(100分)

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

philips

Unregistered / Unconfirmed
GUEST, unregistred user!
Image不能动态改变width,heigth的情况??改了也无法在增大后的区域绘图!!
我发现 liuchuanbo 的 方法不行,再次发贴请大家讨论这个问题。
 
philips:你试过我的回答吗.
 
To :
Fudei

我试过你的方法,不过我是用鼠标通过拖动方法来确定Image的大小,以pixel绘图,

第一次正确,第二次如果绘图区小,还可以,大了则不行。
 
既然第一次可以,那么你可以试着每次确定大小后,绘图前动态创建Image元件,

这样问题不就解决了吗。
 
philips: 我不是说得吗. 你要想图象完全覆盖image(图象大小<image)
就使用image的属性stretch=True; autosize=false;
 
啊! 被吃了部分,再来:
philips: 我不是说得吗. 你要想图象完全覆盖image(图象大小小于image)
就使用image的属性stretch=True; autosize=false;
 
过会儿,我把代码贴出来,大家帮我侃侃。
 
//---------------------------------------------------------------------
#include <vcl.h>
#include <math.h>
#pragma hdrstop
#include "Child0form.h"
//---------------------------------------------------------------------
#pragma resource "*.dfm"

TPoint StartPt,EndPt;
bool bDrawing = False, bDraging = False;

//---------------------------------------------------------------------
__fastcall TfrmChild0::TfrmChild0(TComponent *Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------

void __fastcall TfrmChild0::Image1MouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
int itop,ileft;

if( bDrawing )
{
bDrawing = False;
Image1->Canvas->Rectangle(StartPt.x,StartPt.y, EndPt.x,EndPt.y);
//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;

itop = Image1->Top;
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(int i=0;i<Image2->Height;i++)
for(int j=0;j<Image2->Width;j++)
{
if( Image2->Canvas->Pixels[j]==clRed )
Image2->Canvas->Pixels[j]=clGreen;
else
Image2->Canvas->Pixels[j]=clRed;
}

Image2->Visible = True;
}
}
//---------------------------------------------------------------------------

void __fastcall TfrmChild0::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 TfrmChild0::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 TfrmChild0::Image2MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
StartPt.x = X;
StartPt.y = Y;
bDraging = True;
}
//---------------------------------------------------------------------------

void __fastcall TfrmChild0::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 TfrmChild0::Image2MouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
bDraging = False;
}
//---------------------------------------------------------------------------

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

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

}
//---------------------------------------------------------------------------

以上为我的代码,我欲选种部分曲线,用拖动的方法移动它。请大家帮忙改改。
 
上面程序 漏掉了 这两行:
#include <vcl.h>
#include <math.h>
 

上面的程序在复制时出了问题, 应该是这样的:

#include <vcl.h>
#include <math.h>
#pragma hdrstop
#include "Child0form.h"

#pragma resource "*.dfm"

TPoint StartPt,EndPt;
bool bDrawing = False, bDraging = False;


__fastcall TfrmChild0::TfrmChild0(TComponent *Owner)
: TForm(Owner)
{
}


void __fastcall TfrmChild0::Image1MouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
int itop,ileft;

if( bDrawing )
{
bDrawing = False;
Image1->Canvas->Rectangle(StartPt.x,StartPt.y, EndPt.x,EndPt.y);
//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;

itop = Image1->Top;
ileft = Image1->Left;
Image2->Height = abs(EndPt.y - StartPt.y);//在这修改Image的大小
Image2->Width = abs(EndPt.x - StartPt.x);//在这修改Image的大小
Image2->Left = (StartPt.x>EndPt.x ? EndPt.x :StartPt.x) +ileft;
Image2->Top = (StartPt.y>EndPt.y ? EndPt.y :StartPt.y) +itop;

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

Image2->Visible = True;
}
}


void __fastcall TfrmChild0::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 TfrmChild0::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 TfrmChild0::Image2MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
StartPt.x = X;
StartPt.y = Y;
bDraging = True;
}


void __fastcall TfrmChild0::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 TfrmChild0::Image2MouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
bDraging = False;
}


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

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

}

 
上面程序 漏掉了 这两行:
#include "vcl.h"
#include "math.h"
 
怎么总是 漏掉小(大)于号?
上面的程序的思路正确吗? 有无更好的方法解决?
 
我快急疯了!Wu....
 
看看以前的解答
 
请各位大侠帮帮我,拜托了!
 
c++? I don't know.
好象觉得你是在image上画线, 当拖动它时就不能在多出的区域画了是吗?
是否你的变量被固定了大小,当你结束image拖动时,就无法按你光标位置
画线了,也可试下image的OnProgress事件.
 
今天有有 5 分,可以全加上。
 
我的程序 是先在image1上画线, 当鼠标在Image1上拖动时,动态绘制巨型橡皮线,

松开鼠标后,确定了Image2的位置和大小,我将 Image2 所覆盖的Image1区域的曲

线复制到 Image2上, 然而,不能按照 Image2 的大小画线。

问题就是这样, 请大侠关注以下。拜托!!!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部