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
 How to use TIELayer.UserData and UserDataLen

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
yogiyang Posted - Jun 02 2016 : 02:38:08
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
5   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Jun 08 2016 : 05:35:41
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
yogiyang Posted - Jun 07 2016 : 07:26:52
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
xequte Posted - Jun 07 2016 : 00:21:12
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
yogiyang Posted - Jun 02 2016 : 10:53:23
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
xequte Posted - Jun 02 2016 : 06:35:13
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