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
 Create Layer from Selection?

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
PeterPanino Posted - Sep 07 2020 : 06:37:40
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.
7   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Sep 11 2020 : 02:32:03
Yes, that is the easiest way.

Nigel
Xequte Software
www.imageen.com
yogiyang Posted - Sep 11 2020 : 00:18:40
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
xequte Posted - Sep 09 2020 : 03:49:47
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
spetric Posted - Sep 08 2020 : 18:24:37
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

xequte Posted - Sep 07 2020 : 22:35:18
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
xequte Posted - Sep 07 2020 : 22:28:21
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
spetric Posted - Sep 07 2020 : 07:20:13
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