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
 Create Layer from Selection?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

PeterPanino

392 Posts

Posted - Sep 07 2020 :  06:37:40  Show Profile  Reply
Is it possible to create a Layer that has the exact shape of the current ImageEnView SELECTION?

Please note that a selection can also have an irregular shape.

spetric

Croatia
307 Posts

Posted - Sep 07 2020 :  07:20:13  Show Profile  Reply
Hi,

Maybe there is a shorter and more elegant way,
but here is how I do it (C++, but it's easy to convert):


TRect selRect;
selRect.left    =  paintView->SelectedRect.x;
selRect.bottom  =  paintView->SelectedRect.y;
selRect.right   =  selRect.left + paintView->SelectedRect.width;
selRect.top     =  selRect.bottom - paintView->SelectedRect.height;
// pointer to original image in paintView.
TIEBitmap *image   = paintView->IEBitmap;
TIEBitmap *tempImg = new TIEBitmap(image, selRect);
TIEBitmap *tempAlpha = new TIEBitmap();
tempAlpha->CopyFromTIEMask(paintView->SelectionMask);
// if original bitmap has alpha channel, we will merge selection 
// and original image alpha channels
if (image->HasAlphaChannel)
   image->MergeAlphaRectTo(tempImg,  paintView->SelectedRect.x,  paintView->SelectedRect.y, 0, 0, tempImg->Width, tempImg->Height);
else
   {
   tempImg->AlphaChannel->Fill(255);
   tempAlpha->CopyRectTo(tempImg->AlphaChannel,  paintView->SelectedRect.x,  paintView->SelectedRect.y, 0, 0, tempImg->Width, tempImg->Height);
   }
// assign tempImage to a new layer
paintView->LayersAdd();
paintView->IEBitmap->Assign(tempImage); // copy with alpha channel
delete tempImage;
delete tempAlpha;


paintView is of type TImageEnView or TImageEnVect.

With best regards,
Siniša
Go to Top of Page

xequte

5500 Posts

Posted - Sep 07 2020 :  22:28:21  Show Profile  Reply
Also, if you are just trying to insert a shape layer for instance, you can use:

var
  sel: TIERectangle;
begin
  if ImageEnView1.Selected then
  begin
    sel := ImageEnView1.SelectedRect;
    ImageEnView1.LayersAdd( ielkShape, sel.x, sel.y, sel.width, sel.height );
    TIEShapeLayer( ImageEnView1.CurrentLayer ).Shape := iesEllipse;
  end;
end;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

xequte

5500 Posts

Posted - Sep 07 2020 :  22:35:18  Show Profile  Reply
Here's another way to create an image layer with the content of the current selection:

// Create image layer from current selection
if ImageEnView1.Selected then
begin 
  bmp := TIEBitmap.create();
  ImageEnView1.CopySelectionToBitmap( bmp, False );
  ImageEnView1.LayersAdd( bmp );
  ImageEnView1.CurrentLayer.PosX := ImageEnView1.SelectedRect.x;
  ImageEnView1.CurrentLayer.PosY := ImageEnView1.SelectedRect.y;
  ImageEnView1.Deselect;
  ImageEnView1.Update();
  bmp.Free;
end;

https://www.imageen.com/help/TImageEnView.CopySelectionToBitmap.html

And there is a built-in method:

https://www.imageen.com/help/TImageEnView.LayersCreateFromSelection.html


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

spetric

Croatia
307 Posts

Posted - Sep 08 2020 :  18:24:37  Show Profile  Reply
Hi Nigel,

That's definitely shorter and more elegant way to add selection as layer.
Does CopySelectionToBitmap method preserves ImageEnView alpha-channel (if it exists)?

By that I mean: if current IEBitmap has alpha channel and selection covers
some areas of image with alpha channel = 0, does CopySelectionToBitmap method
creates bitmap with resulting alpha-channel being intersection of selection mask and image alpha channel?

Siniša

Go to Top of Page

xequte

5500 Posts

Posted - Sep 09 2020 :  03:49:47  Show Profile  Reply
Hi Sinisa

Yes, the alpha channel is copied too.

// Save the selected image to PNG (including alpha channel information)
bmp := TIEBitmap.Create;
ImageEnView1.CopySelectionToIEBitmap( bmp, False ) ;
bmp.Write( 'D:\out.png' );
bmp.free;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

yogiyang

India
625 Posts

Posted - Sep 11 2020 :  00:18:40  Show Profile  Reply
Can't we just use:
ImageEnView1.LayersCreateFromSelection;


In my experience this will create a layer based on selection and if there is no selection it will duplicate currently active layer.


Yogi Yang
Go to Top of Page

xequte

5500 Posts

Posted - Sep 11 2020 :  02:32:03  Show Profile  Reply
Yes, that is the easiest way.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To: