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 remove all Layers of certain type?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

yogiyang

India
727 Posts

Posted - Jul 26 2016 :  11:35:48  Show Profile  Reply
Hello,

I want to remove all Mask Layers from a file which contains around 59 layers in all. From these 16 layers are Mask Layers.

For this I am using a for loop from 1 to layers count.

But as the value of loop count goes higher I am getting out of bounce error.

I also ties to run the loop in reverse but that also did not work.

What is the easy way to do this?

TIA


Yogi Yang

w2m

USA
1990 Posts

Posted - Jul 26 2016 :  11:54:39  Show Profile  Reply
You probably can do this by giving each MaskLayer a LayerName when the layer is created and then iterate though the layers backwards to identify the mask layers.

Add Mask Layer
iLayer := ImageEnView.LayersAdd;
ImageEnView.Layers[iLayer].Name := AnsiString('Mask Layer');

Remove all Mask Layers
for i := ImageEnView.LayersCount - 1 downto 1 do
  begin
   ImageEnView.LayersCurrent := i;
   if ImageEnView.CurrentLayer.Name := AnsiString('Mask Layer') then
     ImageEnView.LayersRemove(i);
  end;
ImageEnView.Update;

You must iterate backwards because you are removing layers. If you iterate forwards then the loop becomes corrupted which will cause an exception. Do not include layer 0 because that is not a mask layer.

I can not comment more because you did not show any code at all.

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

38611 Posts

Posted - Jul 26 2016 :  18:12:51  Show Profile  Reply
Thanks Bill

You can also check the IsMask property:

   if ImageEnView.CurrentLayer.IsMask then
     ImageEnView.LayersRemove(i);


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

yogiyang

India
727 Posts

Posted - Jul 27 2016 :  08:28:05  Show Profile  Reply
Bill and Nigel,

Thanks for the feedback.

Actually I was going out of office so I posted the query in a hurry and forgot to post the code.

But now with the help of Bills code I have managed to solve the problem.

Thanks again.

Regards,


Yogi Yang
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: