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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Rotate and crop

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
spetric Posted - Jan 21 2020 : 06:13:47
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
5   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Jan 23 2020 : 13:43:05
Nice.

Nigel
Xequte Software
www.imageen.com
spetric Posted - Jan 23 2020 : 03:44:43
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


xequte Posted - Jan 22 2020 : 14:38:17
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
spetric Posted - Jan 22 2020 : 14:26:18
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.
xequte Posted - Jan 21 2020 : 19:47:29
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