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 use TIELayer.UserData and UserDataLen
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

yogiyang

India
727 Posts

Posted - Jun 02 2016 :  02:38:08  Show Profile  Reply
Hello,

I would like to know as to how to use TIELayer.UserData and TIELayer.UserDataLen practically.

Why I want to do this? Coz I want to store some origianl information with each layer and store the transformation info also like if the layer is rotated then how much it is rotated, if it is resized the how much (%) bigger or smaller it is from original size, etc.

If there is any sample that support this then please point me to this.

Can we point the TIELayer.UserData to a well defined structure or should it be a string variable?

TIA


Yogi Yang

xequte

38940 Posts

Posted - Jun 02 2016 :  06:35:13  Show Profile  Reply
Hi Yogi

The best way is to define a record type. Use New() to create a new variable of that type, set it, and then assign its pointer to TIELayer.UserData and its size to TIELayer.UserDataLen.

Something like (off the top of my head):

type
  TMyRecord = record
    Width, Height: integer;
    Text: array[0..255] of AnsiChar;
  end;
  PMyRecord = ^TMyRecord;


var
  rc: PMyRecord;
begin
  New( PMyRecord )
  With rc^ do
  begin
    Width := ...;
    Height := ...;
    Text := ...;
  end;
  ImageEnView1.CurrentLayer.UserData := rc;
  ImageEnView1.CurrentLayer.UserDataLen := SizeOf( PMyRecord );
end;



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

yogiyang

India
727 Posts

Posted - Jun 02 2016 :  10:53:23  Show Profile  Reply
Nigel,

Thanks. You got me started.

Here is how I am using this:

type
  TMyRecord = record
    MyWidth, MyHeight: integer;
    MyX, MyY: Integer;
    MyRotation: Double;
    MyFileName: String[255];
  end;

var
  PMyRecord: ^TMyRecord;
begin
  New(PMyRecord);
  PMyRecord^.myWidth := iImgWidth;
  PMyRecord^.myHeight := iImgHeight;
  PMyRecord^.MyX := 0;
  PMyRecord^.MyY := 0;
  PMyRecord^.MyRotation := 0;
  PMyRecord^.MyFileName := ''; //Layer 0 has not file attached to it

  ievMain.Layers[0].UserData := PMyRecord;
  ievMain.Layers[0].UserDataLen := SizeOf(PMyRecord);
end;


But now I am facing another problem.

In the file in question there can be n number of layers. Again this is not fixed as to now many layers there will be. So in this case how can I store unique User Data for each layer?

If I use the above code repeatedly for each layer then I think the information will get replaced for all layers User Data.

Finally how do I read back this data?

This code in is not working...

procedure TfrmMain.ievMainLayerNotify(Sender: TObject; layer: Integer;
  event: TIELayerEvent);
type
  TMyRecord = record
    MyWidth, MyHeight: integer;
    MyX, MyY: Integer;
    MyRotation: Double;
    MyFileName: String[255];
  end;
var
  PMyRecord: ^TMyRecord;
begin
  New(PMyRecord);

  ievMain.Layers[layer].UserData := PMyRecord;
  ievMain.Layers[layer].UserDataLen := SizeOf(PMyRecord);

  ShowMessage(PMyRecord^.MyFileName);
end;


TIA


Yogi Yang
Go to Top of Page

xequte

38940 Posts

Posted - Jun 07 2016 :  00:21:12  Show Profile  Reply
Hi Yogi

Why would it matter if you have multiple layers? For each layer you have created [the memory for] a new record.


type
  TMyRecord = record
    MyWidth, MyHeight: integer;
    MyX, MyY: Integer;
    MyRotation: Double;
    MyFileName: String[255];
  end;

// Display the layer filename
procedure TfrmMain.ievMainLayerNotify(Sender: TObject; layer: Integer;
  event: TIELayerEvent);
var
  PMyRecord: ^TMyRecord;
begin
  PMyRecord := ievMain.Layers[layer].UserData;
  ShowMessage(PMyRecord^.MyFileName);
end;




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

yogiyang

India
727 Posts

Posted - Jun 07 2016 :  07:26:52  Show Profile  Reply
Nigel,

Finally I have got it working.

But this data is not getting saved to file when I save the file using:
SaveToFileAll(VectorPageFileName, ioPNG);


I think the data associated with a layer should also get saved to file when we are using SaveToFileAll.

Can you please verify this and help me out.

TIA




Yogi Yang
Go to Top of Page

xequte

38940 Posts

Posted - Jun 08 2016 :  05:35:41  Show Profile  Reply
Hi Yogi

No, it is not saved, but we will look at this for a future version.



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