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
 Free Rotate Multiple layers
 New Topic  Reply to Topic
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

DMC02766

USA
27 Posts

Posted - Apr 13 2016 :  16:49:27  Show Profile  Reply
Hi-
In the project I am working on I have an image with multiple layers that I would like to rotate at once with the mouse (an image with an annotation layer). With the code I am using now, the rotating part works fine but when I finalize the rotation, the layers move from the location they were before finalizing the rotation. Is there a way to keep these layers lined up once the rotation is finalized? I am probably missing something simple but I have been racking my brain trying to figure out what Im doing wrong. I am using one button to start and end the rotation (speedbutton15) Here is the code I am using:


if SpeedButton15.Down then
  begin

  imgview2.LayersRotationAntialias := true;
  imgview2.LayersRotationUseFilterOnPreview := true;
   imgview2.LayersRotationDelayFilterOnPreview := false;
 imgview2.LayersRotationFilter := ierfast;
   imgview2.SelectionOptions := [iesoselecttransplayers];
    Imgview2.LayersFixSizes(Imgview2.LayersCurrent);
    imgview2.LayersFixRotations(Imgview2.LayersCurrent);
   imgview2.LayersFixborders(Imgview2.LayersCurrent);
    imgview2.AutoFixRotationBorders := false;

    imgview2.MouseInteract := [miRotateLayers];


  end
   else
     imgview2.MouseInteract := [];
     imgview2.Cursor := crDefault;

  end;



Thanks for any help that can be offered, I much appreciate it.

w2m

USA
1990 Posts

Posted - Apr 13 2016 :  17:16:15  Show Profile  Reply
I suspect all you need in the SpeedButtonOnClick event is
imgview2.MouseInteract := [miRotateLayers] because when you click on the button the layer has not been rotated yet, but you are fixing sizes, fixing rotations and fixing borders... this is clearly incorrect. You should also set any general layer options or properties in the OnFormCreate event:

Here when I rotate with the mouse the layers remain as they were when rotated. The position of the layer does not change after the rotation.

What do you mean by "when I finalize the rotation". What, why and how are you finalizing the rotation? Do you mean when the speed button is up? If so then try this:

procedure TForm1.FormCreate(Sender: TObject);
begin
  { initialize options and properties here }
  ImageEnView1.IO.Params.BMP_HandleTransparency := True;
  { Select transparent layers }
  ImageEnView1.SelectionOptions := ImageEnView1.SelectionOptions +
    [iesoSelectTranspLayers];
end;

if SpeedButton15.Down then
begin
   imgview2.MouseInteract := [miRotateLayers];
end
else
   imgview2.MouseInteract := [];
   imgview2.Cursor := crDefault;
end;

If this does not work as you expect then provide a small demo that can be reviewed. Are you using any other events for layers especially the OnLayerNotify event?

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

DMC02766

USA
27 Posts

Posted - Apr 13 2016 :  17:28:33  Show Profile  Reply
Thanks for your input but that made the second layer jump to the corner of the first layer. I had tried this to begin with and is actually why I put in the fixing sizes, fixing rotations and fixing borders which maintained all of the layers to the same position / center when rotating. When I said finalize, I meant when the button was up which completed the rotating of the layers. I will put together a small demo which may help to see what it is doing.
Go to Top of Page

w2m

USA
1990 Posts

Posted - Apr 13 2016 :  17:36:35  Show Profile  Reply
I think when you complete your demo you will find that it works correctly. I suspect you are changing the layer positions in another event somehow because layers do not jump around without code that causes them to do so. All the extra code you are using is simply not necessary. I'd look for some code elsewhere in you app that repositions the layers somehow. Are you setting Layer[LayersCurrent.PosX or Layer[LayersCurrent.PosY in another event?

I suspect you have ImageEnView1.LayersSync := False set. I would put ImageEnView1.LayersSync := False in the OnFormCreate event along with the other code I posted for that event.

When you finish the demo and the layers are still jumping around post it and I'll review your code.

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

DMC02766

USA
27 Posts

Posted - Apr 14 2016 :  09:24:17  Show Profile  Reply
Included is a small demo with two rotation buttons. Button A is using just the imgview1.MouseInteract := [mirotatelayers] whereas buttonB is going through all of the code I had before. I will attach the image that I am using with the annotations layer on it in a separate post so you can see exactly what I am seeing with it. If I load the image and click buttonb first, it rotates fine then when the button is up, the annotations layer jumps to another location. If I load the image and click buttonA first, the annotation layer immediately jumps to the top left corner and rotates separately from the layer 0 image. I also noticed buttonB, when up takes it a minute to set the image following rotating. Let me know your thoughts when you get a chance. Again- I greatly appreciate your help and insight by taking time out of your day to help me.

attach/DMC02766/201641491725_RotateDemo.zip
5826.77 KB
Go to Top of Page

DMC02766

USA
27 Posts

Posted - Apr 14 2016 :  09:29:15  Show Profile  Reply

Here is the sample image I am testing with and the layer file that goes along with it. I had to put them in two separate zip files because they hit the 10 mb limit when I tried to do them together. The sample program loads the file and then the layer so just put them in the same location when testing.

attach/DMC02766/20164149266_image.zip
5101.55 KB



attach/DMC02766/20164149276_imagelayer.zip
5781.71 KB
Go to Top of Page

w2m

USA
1990 Posts

Posted - Apr 14 2016 :  12:59:52  Show Profile  Reply
A couple things I found from your demo:

1. LayersLoadFromFile loads the same image layer 0 as LoadFromFile plus any other layers in the lyr file. The lyr file contains all layers including the image in layer 0 so it is not to correct to use both LoadFromFile and use LayersLoadFromFile.

2. I found that the layer movement was caused by the rotated background image in layer 0. After I cropped the image to its original dimensions without rotation, then layer 1 rotates correctly and does not move. I have never seen a background image saved like this before so I never have encountered the problem in the past.

To solve the problem I cropped the image in layer 0 so it was not rotated and saved to a new layer file. Now when loading the new lyr file and you rotate and there is no jumping of the layer position and rotation works as expected.

You may download the revised demo here:
attach/w2m/2016414103855_RotateDemo.zip
6827.23 KB
I only changed how you were loading the file and added a few buttons to control selecting and rotating layers. You probably can change it back to use the original speed buttons if you wish.

You may download the new layer file here:
attach/w2m/2016414104042_Image.zip
4842.86 KB
Another demo which you may like which allows speed drawing with a brush in a layer as well as showing how to work with layers may be downloaded here:
attach/w2m/2016414125849_PaintBrush.zip
90.75 KB
If you still have problems let me know and I'll investigate further.

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

DMC02766

USA
27 Posts

Posted - Apr 14 2016 :  15:44:26  Show Profile  Reply
Thanks for checking it out. I'm still having some issues with it although I think I have narrowed down what is happening but am not sure how to correct it. It looks as though when I go to rotate the two layers, if it has a transparent layer with annotations on it, it is cropping the transparent areas around the annotations then moving it. If I draw an "x" from corner to corner then save / rotate, it works correctly although if I draw something inside that doesn't touch the edges of layer 0, it crops the annotation layer on rotate. If you would like to see, I can add the drawing part I am using to the demo. I am testing with an image that was not previously rotated and am getting the same results. All seems to be good until the layers are rotated though.

Thanks for the heads up on the loading of the layers as well. I have recoded it to check if there is a .lyr file and if not then it just loads the image, otherwise it just loads the .lyr file.
Go to Top of Page

DMC02766

USA
27 Posts

Posted - Apr 14 2016 :  15:52:02  Show Profile  Reply
Just tried something else- I tried adding the new layer then sizing it to layer 0:


  imgview1.LayersAdd;
      Imgview1.Layers[1].PosX := 0;
Imgview1.Layers[1].PosY := 0;
Imgview1.Layers[1].Width := imgview1.Layers[0].Width;
Imgview1.Layers[1].Height := imgview1.Layers[0].Height;


So it should add a layer before the annotations are made on it the same size as layer 0. Once saved it all looks good, but if I rotate it, then the annotations expand to the size of layer 0.
Go to Top of Page

w2m

USA
1990 Posts

Posted - Apr 14 2016 :  17:49:09  Show Profile  Reply
Are you trying to rotate 2 layers at the same time? I just tested this here and I can rotate two layers at the same time and they rotate correctly and maintain their position.If not then I have no idea why you see layer movement, because I do not see that here at all with either of the demos I posted. LayersSync my be False. Is it in your test? If not all layers will be the same as layer 0.

Also what do you mean by annotation? A brush line or a object? The two demos do not use objects at all.

With respect to TImageEnVect how are you setting the objects layer? If you do not set the objects layer the objects are set to be drawn on the top of all layers. If you set the objects layer then they will be drawn only on the current layer. This may be your problem.

TImageEnVect.ObjLayer

Declaration

property ObjLayer[hobj: integer]: integer;

Description

Specifies layer index where the object is located (drawed and referenced). Default is "0" and means draw on layer 0.
hobj is the ID of the object. You can also specify IEV_NEXT_INSERTED_OBJECT (-1) which refers to the next object to be inserted or IEV_PREVIOUS_INSERTED_OBJECT (-2) for the last object inserted.

var
  ihObj: Integer;
begin
    ihObj := ImageEnVect1.AddNewObject;
    ImageEnVect1.ObjLayer[ihObj] := ImageEnVect1.LayersCurrent;



TImageEnVect.ObjAnchorToLayers

Declaration


property ObjAnchorToLayers: boolean;

Description

When true (default), all objects are anchored to a layer (using ObjLayer property). Otherwise (the old behavior) objects are just painted over all layers.
procedure TForm1.FormCreate(Sender: TObject);
begin
  ImageEnVect1.ObjAnchorToLayers := True;
end;


As a last resort what is version of ImageEn are you using? I know that layer rotation was improved in the latest version of ImageEn, so that may also be your problem. I am using version 6.2.2.

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

DMC02766

USA
27 Posts

Posted - Apr 15 2016 :  12:05:20  Show Profile  Reply
Thanks again for your detailed quick responses, I really appreciate it. What I am trying to accomplish is to be able to draw on a separate layer from layer 0 and be able to rotate all of the layers together. The lines that are drawn line up with lines in layer 0 and should remain in the same position when rotated. I am using objects to draw the lines on the layers and am currently using version 6.2.2 of the software.

I have included another demo, this time with the code I am using for drawing the lines / adding the layers. I can draw a line but when I go to rotate is when it sizes the drawing layer (whether saved or not) and rotates out of its original location.

When you get a chance if you dont mind looking at it, I would greatly appreciate it. Thanks again for all of the help- you have really gone above and beyond to help me and it means a lot.

attach/DMC02766/201641512421_rotatedemo2.zip
5992.6 KB
Go to Top of Page

w2m

USA
1990 Posts

Posted - Apr 15 2016 :  15:01:40  Show Profile  Reply
I did some checking with TImageEnVect, objects and layer rotation last night. What I found was that after the layer is created and objects are added to a layer (with objects anchored to the current layer), then the layer is rotated, the layer does indeed jump to the center of the screen (probably because I have the Center property set to true. Thus this is similar to the results you are seeing after the layer is rotated.

I do not know of any way to resolve this problem specifically. You could try to draw a line or brush where you need them to appear, so then when you rotate a layer all the lines rotate with the layer. With GDI drawing, the layer position does not change. Individual lines can not be rotated individually unless you put each line in its own layer, so I am not sure if this will be useful for you.

The brush and line drawing is demonstrated in the later of the two demos I posted.

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

DMC02766

USA
27 Posts

Posted - Apr 18 2016 :  08:55:00  Show Profile  Reply
Thanks for taking the time to check into it Bill. At least I know I'm not seeing things. Is there a way to put in a support ticket to have it looked into for possible later versions of the software? I wasnt sure if there was a way to do that other than emailing Nigel.

Thanks again for all of your help!
Go to Top of Page

xequte

39053 Posts

Posted - Apr 20 2016 :  15:48:17  Show Profile  Reply
Hi

We'll look into this shortly.



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

DMC02766

USA
27 Posts

Posted - Apr 20 2016 :  15:49:09  Show Profile  Reply
Thanks Nigel!
Go to Top of Page

xequte

39053 Posts

Posted - Apr 27 2016 :  23:20:46  Show Profile  Reply
Hi

I can reproduce this with your EXE, but not when I recompile with the 6.2.3 Beta. You should email me for the source code to confirm the issue is fixed.



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

w2m

USA
1990 Posts

Posted - Apr 28 2016 :  07:29:45  Show Profile  Reply
Did you make changes to 6.2.3 with respect to this, as I tested with 6.2.2?

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

39053 Posts

Posted - Apr 28 2016 :  23:51:51  Show Profile  Reply
Hi Bill

I can't see any changes that should affect this, but i cannot reproduce it when recompiling the code. The other possibility is a Delphi version issue, but I've emailed him the source to test, so lets await the result of that.



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

DMC02766

USA
27 Posts

Posted - May 06 2016 :  09:00:17  Show Profile  Reply
I have finally had a chance to test it out and it appears that the issue is still there. I have also tried it with 6.3.0 and the problem still exists in that version as well.
Go to Top of Page

xequte

39053 Posts

Posted - May 07 2016 :  00:09:02  Show Profile  Reply
OK, then it must only happen in certain Delphi versions. What version are you using?



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

DMC02766

USA
27 Posts

Posted - May 09 2016 :  09:56:11  Show Profile  Reply
I am using Delphi 10 Seattle.
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Reply to Topic
Jump To: