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
 How to crop the image to the painted rectangle?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

klinikaxp

Poland
11 Posts

Posted - Aug 28 2017 :  09:27:23  Show Profile  Reply
I have a device, which enables to draw a signature using special pen.
It is stored on the hard drive as a bitmap. However stored area is big and signature takes only small part of it. Is there any way to easily crop only part of on image, which contains the signature? It could be something like procedure TImageEn.ReduceToPainted (Margins:Integer; BackColor:TColor=clWhite);
or conversion function:
function ReduceToPainted (src:SrcBitmap; Margins:Integer; BackColor:TColor=clWhite) : TBitmap;

Maybe there is something like this already implemented?

w2m

USA
1990 Posts

Posted - Aug 28 2017 :  10:27:16  Show Profile  Reply
There are no functions that I am aware of that will select the area around the text for cropping. If the signature image background is white and the text is black then the following will work quite well:
ImageEnView1.SelectColors(TColor2TRGB(clBlack));
ImageEnView1.Proc.CropSel();
ImageEnView1.Deselect;

If the text color is blue then replace clBlack with clBlue.
In my tests, this reduced a 256x256 signature image to 115x115.

Also if the location of the signature is in the same location in your images you can just set the selection to the proper dimensions and then crop the selection:
{ Figure out the area to select and add those values to the following}
ImageEnView1.Select(100, 900, 150, 100); 
{ Crop  the selection }
ImageEnView1.Proc.CropSel();
ImageEnView1.Deselect;

You could also try:
ImageEnView1.Select(100, 900, 150, 100);
ImageEnView1.SaveSelectionToFile('Signature');

Then when you want to crop the image call LoadSelectionFromFile and crop:
ImageEnView1.LoadSelectionFromFile('Signature');
ImageEnView1.Proc.CropSel();
ImageEnView1.Deselect;

Also see:
procedure SaveSelection and RestoreSelection.
Description
Adds the current selection to the stack (selections list).

Example
ImageEnView1.Select(10, 10, 100, 100);
ImageEnView1.SaveSelection;
ImageEnView1.Select(200, 200, 150, 150);
ImageEnView1.SaveSelection;
ImageEnView1.Deselect;

ImageEnView1.RestoreSelection; // reload 200,200,150,150
..
ImageEnView1.RestoreSelection; // reload 10,10,100,100

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

xequte

38222 Posts

Posted - Aug 28 2017 :  17:02:30  Show Profile  Reply
Also, have you tried the auto-cropping methods, such as:

https://www.imageen.com/help/TImageEnProc.AutoCrop.html


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

klinikaxp

Poland
11 Posts

Posted - Aug 28 2017 :  17:31:13  Show Profile  Reply
Thank you for quick answer and functionality - it was exactly what I was looking for!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: