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
 Convert TImageEnView image into a manipulable layer?

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 - Jan 13 2024 : 15:07:49
What is the best (easiest) way to convert the loaded image of a TImageEnView into an image layer that can be manipulated with the Layer Properties dialog and resized with the mouse?
7   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Jan 19 2024 : 21:34:56
Hi Peter

Yes, the code in the demo looks OK.

Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Jan 17 2024 : 01:29:46
The attached project TransformImageToLayer2.zip clearly demonstrates how it works:

https://app.screencast.com/y8clbqdOnYdQS
xequte Posted - Jan 16 2024 : 18:50:29
Sorry, I'm not really following what you are trying to do here.

I presume by "transform the image into a layer" you mean you are wanting to make an image layer moveable and sizable? (note that images are always layers in TImageEnView)?

But then what are you wanting when you "transform a layer into an image"?



Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Jan 14 2024 : 14:15:06
I have now created a solution that works for me:

procedure TForm1.ButtonTransformImageTolayerClick(Sender: TObject);
begin
  // Remember old bitmap dimensions:
  var OldW := ImageEnView1.IEBitmap.Width;
  var OldH := ImageEnView1.IEBitmap.Height;
  ImageEnView1.IEBitmap.Clear; // Set Image-Bitmap to Zero
  // restore previous Bitmap dimensions, to correctly restore positions when merging later:
  ImageEnView1.IEBitmap.Width := OldW;
  ImageEnView1.IEBitmap.Height := OldH;

  AddImageLayerFromFile(FCurrentImageSVGFile);
  ImageEnView1.Update();
  ImageEnView1.MOuseInteractLayers := [mlResizeLayers, mlMoveLayers, mlRotateLayers];
  ButtonTransformLayerToImage.Enabled := True;
end;

procedure TForm1.ButtonTransformLayerToImageClick(Sender: TObject);
begin
  ImageEnView1.LayersMerge(0, FNewLayer);
end;


attach/PeterPanino/2024114141211_TransformImageToLayer2.zip
80.28 KB

If you have any suggestions for improving this solution, please proceed.
PeterPanino Posted - Jan 14 2024 : 04:17:16
Hi Nigel,

My intent was to:

1. Transform the image to a Layer
2. Manipulate the Layer with Layer methods (such as Resize with the mouse)
3. Transform the Layer back to the Image

I have tried it with this code:

procedure TForm1.FormCreate(Sender: TObject);
var
  ExePath: string;
begin
  ExePath := System.SysUtils.IncludeTrailingPathDelimiter(ExtractFilePath(Application.ExeName));
  ImageEnView1.IO.ImportFromFileSVG(ExePath + 'SUNRISE.svg', 1000, -1, True);
end;

procedure TForm1.ButtonTransformImageTolayerClick(Sender: TObject);
begin
  ImageEnView1.LayersCurrent := 0;
  ImageEnView1.CurrentLayer.Selectable := True;
  ImageEnView1.CurrentLayer.VisibleBox := True;
  ImageEnView1.CurrentLayer.Locked := False;
  ImageEnView1.CurrentLayer.Locked := False;
  ImageEnView1.CurrentLayer.AspectRatioLocked := True;
  ImageEnView1.CurrentLayer.Width := 400;
  ImageEnView1.CurrentLayer.Height := 400;
  ImageEnView1.Update();

  ImageEnView1.MOuseInteractLayers := [mlResizeLayers, mlMoveLayers];

  Self.ActiveControl := ImageEnView1;
  ImageEnView1.SetFocus;

  ImageEnView1.CurrentLayer.Selected := True;

  FNewLayer := ImageEnView1.LayersCurrent;

  ButtonTransformLayerToImage.Enabled := True;
end;

procedure TForm1.ButtonTransformLayerToImageClick(Sender: TObject);
begin
  //ImageEnView1.LayersMerge(0, FNewLayer); // Error: List index out of bounds (0). TList is empty.
  // How to transform Layer back to Image?
end;


attach/PeterPanino/202411441615_TransformImageToLayer.zip
80.08 KB
xequte Posted - Jan 13 2024 : 21:14:45
Hi

To load a layer and make it sizeable use:

ImageEnView1.IO.LoadFromFile( 'D:\im.jpg' );
ImageEnView1.CurrentLayer.Selectable := True;
ImageEnView1.CurrentLayer.VisibleBox := True;
ImageEnView1.CurrentLayer.Locked := False;
ImageEnView1.CurrentLayer.Locked := False;
ImageEnView1.Update();

ImageEnView1.MOuseInteractLayers := [mlResizeLayers, mlMoveLayers];


Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Jan 13 2024 : 15:24:14
I've tried the following:

procedure TForm1.mTransformToImageLayerClick(Sender: TObject);
var
  NewLayerIndex: Integer;
begin
  with ImageEnView1 do
  begin
    // Add a new image layer:
    NewLayerIndex := LayersAdd(ielkImage, 0, 0, IEBitmap.Width, IEBitmap.Height);

    // Assign the background image to the new image layer:
    Layers[NewLayerIndex].Bitmap.Assign(IEBitmap);

    // Clear the original background image:
    ImageEnView1.IEBitmap.Clear;

    // Set the properties of the new layer, including transparency
    with Layers[NewLayerIndex] do  // Index is now NewLayerIndex - 1 because we deleted a layer
    begin
      Opacity := 128; // Adjust transparency (0: fully transparent, 255: fully opaque)
      Selectable := True;
      Visible := True;
      VisibleBox := True;
      ResampleFilter := rfLanczos3;
      AntiAlias := True;
      AspectRatioLocked := True;
    end;

    // Update the view
    Update;
  end;
end;


But as soon as I resize the new Layer with the mouse, its layer grips vanish (while the original image remains visible).