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
 Rotate and crop
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

spetric

Croatia
252 Posts

Posted - Jan 21 2020 :  06:13:47  Show Profile  Reply
Hi,

Here is a scenario:

1. There is only one layer (background image).
2. Layer is rotated (preview) using standard set of parameters:

    PaintView->Layers[0]->RotateCenterX = editCenterX->FloatValue;
    PaintView->Layers[0]->RotateCenterY = editCenterY->FloatValue;
    PaintView->Layers[0]->Rotate = editAngle->IntValue;

2. When button is clicked, original (unrotated) bitmap is copied to work bitmap.
3. Work bitmap is rotated using ImageEnProc Rotate method with the same angle.
4. Original image is filled with some predefined background color.
5. Work bitmap (rotated) is copied to original bitmap using CopyRect method (work bitmap is actually cropped).

The question is: Is there an information about X/Y shift amount (already calculated) that can be used as a srcX/srcY value for CopyRect method.

To be more clear, here is a picture (preview):




So, to simplify my question: How to crop rotated image to fit original rectangle?
When CopyRect method is used and scrX, srcY, dstX, dstY values are zero, cropped (rotated) image is shifted to the right and down.

Edit: I've tried to get some relevant data from PaintView->Layers[0]->DrawingInfo, but don't know how to interpret them.

TIA,
Siniša

xequte

4981 Posts

Posted - Jan 21 2020 :  19:47:29  Show Profile  Reply
Hi Sinisa

You can use:

TIEImageLayer( ImageEnView1.CurrentLayer) .RotatedClientAreaPts[];

It is an array [0..3] of TPoint of the four corners of the rotated image.


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

spetric

Croatia
252 Posts

Posted - Jan 22 2020 :  14:26:18  Show Profile  Reply
Hi Nigel,

I've tried to use RotatedClientAreaPts, but then I must compare it with clientbox area and then again with original image rectangle to get shift values for CopyRect method.

So, I've done it manually. As I already have method for rotating array of TPoint by arbitrary angle around some origin, I've passed array of image corners and apply rotation. Then, I found minX and minY from rotated points and used those values for CopyRect method:


workMap->CopyRectTo(ImageContainer->ImageOrig->ieBitmap, 0, 0, minX, minY, workMap->Width, workMap->Height);


It works as supposed.
Thanks.
Go to Top of Page

xequte

4981 Posts

Posted - Jan 22 2020 :  14:38:17  Show Profile  Reply
Hi Sinisa

Sorry, I cannot think of a better way to get those values. ImageEn itself just gets the four corner points and then rotates each of them using:

procedure IERotatePoints(var rpt: array of TPoint; PointCount: Integer; Angle: double; CenterX, CenterY: integer);

(from hyieutils.pas)

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

spetric

Croatia
252 Posts

Posted - Jan 23 2020 :  03:44:43  Show Profile  Reply
Hi Nigel,

Your suggestion (4 corners) gave me an idea and led me in right direction and relatively simple solution.

As you may notice from the attached image (example), rotating 4 corners produces negative X value for top-left corner and negative Y value for top-right corner.

When these values are used as destX and destY in CopyRect method, everything works fine. It also works well for all rotation center values and various angles.

Thanks a lot,
Siniša


Go to Top of Page

xequte

4981 Posts

Posted - Jan 23 2020 :  13:43:05  Show Profile  Reply
Nice.

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