Page 1 of 1

Image Stretching in CadviewX

Posted: 31 Mar 2007, 19:30
by lordjim
As a new user to CadviewX I have a (hopefully) simple question. Is it possible to have CadviewX stretch the image to fill the frame, regardless of the aspect ratio? That would be very helpful to me in the application I'm developing.


"God as my witness, Andy, I thought turkeys could fly."

Posted: 03 Apr 2007, 10:44
by support
Hello!

Here goes Delphi example:

Code: Select all

<b>uses</b>
  ... CADViewLib_TLB;
...

<b>type</b>
  TForm1 = <b>class</b>(TForm)
    Button1: TButton;
    CADViewX1: TCADViewX;
    Image1: TImage;
    <b>procedure</b> Button1Click(Sender: TObject);
...

<b>procedure</b> TForm1.Button1Click(Sender: TObject);
<b>var</b>
  vClientRect: TxRectLong;
  vSourceRect: tagFRectLong;
<b>begin</b>
  vClientRect.Left := Image1.ClientRect.Left;
  vClientRect.Top := Image1.ClientRect.Top;
  vClientRect.Right := Image1.ClientRect.Right;
  vClientRect.Bottom := Image1.ClientRect.Bottom;
  vSourceRect := CADViewX1.DXFImage.Extents;

  CADViewX1.DXFImage.DrawRect(Image1.Canvas.Handle, vSourceRect, vClientRect);
<b>end</b>;

<b>end</b>.
Sergey.

Please post questions to the forum or write to support@cadsofttools.com

Posted: 04 Apr 2007, 16:09
by duw
IÒ‘ve tried the above code. But got a few doubts:

What is the purpose of the TImage "Image1" declared in the unit? It should be at an specific position for the stretch method to work?

Here i just inserted the TImage in the middle of the form for the method do compile, but it does nothing on run-time.

lordjim: did you make it work?


Thanks,
Eduardo

Posted: 04 Apr 2007, 16:38
by support
Hello Eduardo.

<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">What is the purpose of the TImage "Image1" declared in the unit?<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
TImage "Image1" was used only as example, which demonstrated how to stretch loaded into CADViewX file regardless of the aspect ratio.
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">It should be at an specific position for the stretch method to work?<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
There is no difference where TImage "Image1" lays. The main are its handle and client rectangle.
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">Here i just inserted the TImage in the middle of the form for the method do compile, but it does nothing on run-time.

lordjim: did you make it work?<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Of course it worked! We have sent you full demo.

Sergey.

Please post questions to the forum or write to support@cadsofttools.com

Posted: 04 Apr 2007, 20:45
by duw
Sent to my e-mail registered?

I got nothing by now... even checked the anti-spam.


Thanks,
Eduardo

Posted: 04 Apr 2007, 20:59
by support
Sent to your e-mail, registered on the forum.
Please contact us to support@cadsofttools.com with a reference on this topic.

Sergey.

Please post questions to the forum or write to support@cadsofttools.com

Posted: 11 Apr 2007, 17:03
by duw
Got the demo. It actually works, but in a different way that i did expect:

- it only makes the stretch in the DWG files. It does not work for images like BMP or GIF;
- it applies the stretch into another component of the form (TImage), not the CadViewX itself.

Now it creates two questions:

1. Does it only applies to CAD images, or is there a way to make it work for all kind of images that the component can read?
2. Can i stretch the image loaded INTO the CadView component, not applying it to an external component?

Thanks again,
Eduardo

Posted: 16 Apr 2007, 13:31
by support
Hello Eduardo.

The following code views how to stretch loaded DXF file into the CADViewX:

Code: Select all

<b>type</b>
  TForm1 = <b>class</b>(TForm)
    CADViewX1: TCADViewX;
    btnDrawDXFtoItself: TButton;
    OpenDialog1: TOpenDialog;    
    procedure CADViewX1Paint(Sender: TObject);
    procedure btnDrawDXFtoItselfClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);    
  <b>private</b>
    FIImg: IDXFImage;    
    <b>procedure</b> StretchImage;
...

<b>procedure</b> TForm1.CADViewX1Paint(Sender: TObject);
<b>begin
  if</b> Assigned(FIImg) <b>then</b>
    StretchImage;
<b>end</b>;

<b>procedure</b> TForm1.btnDrawDXFtoItselfClick(Sender: TObject);
<b>begin
  if not</b> OpenDialog1.Execute <b>then</b>
    Exit;
  
  FIImg := CoDXFImage.Create;
  FIImg.CreateImage;
  FIImg.LoadFromFile(OpenDialog1.FileName);
  CADViewX1.Invalidate;
<b>end</b>;

<b>procedure</b> TForm1.FormDestroy(Sender: TObject);
<b>begin</b>
  FIImg :=  <b>nil</b>;
<b>end</b>;

<b>procedure</b> TForm1.StretchImage;
<b>var</b>
  vClientRect: TxRectLong;
  vSourceRect: tagFRectLong;  
<b>begin</b>
  vSourceRect := FIImg.Extents;
  vClientRect := CADViewX1.ImageBoundsRect;
  vClientRect.Bottom := vClientRect.Bottom <b>div</b> <font color="blue">2</font id="blue">;
  FIImg.DrawRect(CADViewX1.hDc, vSourceRect, vClientRect);
<b>end</b>;
The following code views how to stretch loaded BMP file into the CADViewX:

Code: Select all

<b>type</b>
  TForm1 = <b>class</b>(TForm)    
    CADViewX1: TCADViewX;        
    OpenDialog1: TOpenDialog;
    btnDrawBMPtoItself: TButton;    
    <b>procedure</b> CADViewX1Paint(Sender: TObject);    
    <b>procedure</b> FormDestroy(Sender: TObject);
    <b>procedure</b> btnDrawBMPtoItselfClick(Sender: TObject);
    <b>procedure</b> FormCreate(Sender: TObject);
  <b>private</b>
    FRasterImg: TCADViewX;
    FPicture: TPicture;
    <b>procedure</b> StretchImage;
...

<b>procedure</b> TForm1.CADViewX1Paint(Sender: TObject);
<b>begin
  if</b> Assigned(FRasterImg) <b>then</b>
    StretchImage;
<b>end</b>;

<b>procedure</b> TForm1.FormDestroy(Sender: TObject);
<b>begin
  if</b> FRasterImg <> <b>nil then</b>
    FRasterImg.Free;
  FPicture.PictureAdapter := <b>nil</b>;
  FPicture.Free;
<b>end</b>;

<b>procedure</b> TForm1.btnDrawBMPtoItselfClick(Sender: TObject);
<b>var</b>
  IPic: IPictureDisp;
<b>begin
  if not</b> OpenDialog1.Execute <b>then</b>
    Exit;
  FRasterImg := TCADViewX.Create(<b>nil</b>);
  FRasterImg.LoadFile(OpenDialog1.FileName);
  IPic := FRasterImg.DefaultInterface.Picture;
  (FPicture.PictureAdapter <b>as</b> IPictureAccess).SetOlePicture(IPic);
  IPic := <b>nil</b>;
  CADViewX1.RefreshAfterRotate;
<b>end</b>;

<b>procedure</b> TForm1.StretchImage;
<b>var</b>
  vClientRect: TxRectLong;
  vSourceRect: tagFRectLong;
  vCanv: TCanvas;
<b>begin</b>
  vClientRect.Left := Image1.ClientRect.Left;
  vClientRect.Top := Image1.ClientRect.Top;
  vClientRect.Right := Image1.ClientRect.Right;
  vClientRect.Bottom := Image1.ClientRect.Bottom;
  vSourceRect := FRasterImg.DXFImage.Extents;
  vClientRect := CADViewX1.ImageBoundsRect;
  vClientRect.Bottom := vClientRect.Bottom <b>div</b> <font color="blue">2</font id="blue">;
  vCanv := TCanvas.Create;
  <b>try</b>
    vCanv.Handle := CADViewX1.hDc;
    vCanv.StretchDraw(TRect(vClientRect), FPicture.Graphic);
  <b>finally</b>
    vCanv.Handle := <font color="blue">0</font id="blue">;
    vCanv.Free;
  <b>end</b>;
<b>end</b>;
Sergey.

Please post questions to the forum or write to support@cadsofttools.com