ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Custom draw crop box
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

hifly

China
6 Posts

Posted - Jun 19 2019 :  21:22:38  Show Profile  Reply
HI.

I am doing portrait collection, using IMAGEEN image component.
Now there is a problem that needs your help to solve.




xequte

38608 Posts

Posted - Jun 19 2019 :  22:18:25  Show Profile  Reply
Hi

You can custom draw on the image view using the OnDrawCanvas event:


// Show a 100x100px box in the center of the image (does not modify the actual image, only the view)
procedure TForm1.ImageEnView1DrawCanvas(Sender: TObject; ACanvas: TCanvas; ARect: TRect);
const
  Box_Width  = 100;
  Box_Height = 100;
var
  boxL, boxT, boxR, boxB: Integer;
begin
  if ImageEnView1.IsEmpty2 or
     ( ImageEnView1.IEBitmap.Width < Box_Width ) or
     ( ImageEnView1.IEBitmap.Height < Box_Height ) or
     not chkDrawBox.Checked then
    exit;

  boxL := ImageEnView1.XBmp2Scr( ImageEnView1.IEBitmap.Width  div 2 - Box_Width  div 2 );
  boxT := ImageEnView1.YBmp2Scr( ImageEnView1.IEBitmap.Height div 2 - Box_Height div 2 );
  boxR := ImageEnView1.XBmp2Scr( ImageEnView1.IEBitmap.Width  div 2 + Box_Width  div 2 );
  boxB := ImageEnView1.YBmp2Scr( ImageEnView1.IEBitmap.Height div 2 + Box_Height div 2 );

  ACanvas.Pen.Color := clRed;
  ACanvas.Brush.Style := bsClear;
  ACanvas.Rectangle( boxL, boxT, boxR, boxB );
end;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

xequte

38608 Posts

Posted - Jun 19 2019 :  22:49:08  Show Profile  Reply
Another example:


// Draw "thirds" within the selection box
procedure TForm1.ImageEnView1DrawCanvas(Sender: TObject; ACanvas: TCanvas; ARect: TRect);
var
  selRect: TIERectangle;
  {}
  procedure _DrawLine(x1, y1, x2, y2: Integer); // bmp values
  begin
    ACanvas.Pen.Color := clGray;
    ACanvas.MoveTo( ImageEnView1.XBmp2Scr( x1 ), ImageEnView1.YBmp2Scr( y1 ) );
    ACanvas.LineTo( ImageEnView1.XBmp2Scr( x2 ), ImageEnView1.YBmp2Scr( y2 ) );
  end;
  {}
begin
  if not ( ImageEnView1.Selected and chkDrawBox.Checked ) then
    exit;

  selRect := ImageEnView1.SelectedRect;

  // Horz Thirds
  _DrawLine( selRect.x, selRect.y + MulDiv( selRect.height, 1, 3 ),
             selRect.x + selRect.Width, selRect.y + MulDiv( selRect.height, 1, 3 ) );
  _DrawLine( selRect.x, selRect.y + MulDiv( selRect.height, 2, 3 ),
             selRect.x + selRect.Width, selRect.y + MulDiv( selRect.height, 2, 3 ) );

  // Vert Thirds
  _DrawLine( selRect.x + MulDiv( selRect.Width, 1, 3 ), selRect.y,
             selRect.x + MulDiv( selRect.Width, 1, 3 ), selRect.y + selRect.height );
  _DrawLine( selRect.x + MulDiv( selRect.Width, 2, 3 ), selRect.y,
             selRect.x + MulDiv( selRect.Width, 2, 3 ), selRect.y + selRect.height );
end;



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

xequte

38608 Posts

Posted - Jun 19 2019 :  22:49:26  Show Profile  Reply
And here is the demo:

attach/xequte/201961922180_SelectAndCrop2.zip
2789.69 KB

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

hifly

China
6 Posts

Posted - Jun 23 2019 :  09:07:25  Show Profile  Reply
@xequte
Thanks for your help. There are two more problems to be solved.
1. How to set the size of the clipping box? (X, Y, Width, Height)
2. Lock the cutting ratio according to the size of the sheet? (Width, Height)
Go to Top of Page

xequte

38608 Posts

Posted - Jun 23 2019 :  21:15:20  Show Profile  Reply
Hi

Please take a look at crop tool demo, it shows locking the crop box:

Demos\ImageEditing\CropTool\CropTool.dpr

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: