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
 Convert TImageEnView image into a manipulable layer?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

934 Posts

Posted - Jan 13 2024 :  15:07:49  Show Profile  Reply
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?

PeterPanino

934 Posts

Posted - Jan 13 2024 :  15:24:14  Show Profile  Reply
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).
Go to Top of Page

xequte

38654 Posts

Posted - Jan 13 2024 :  21:14:45  Show Profile  Reply
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
Go to Top of Page

PeterPanino

934 Posts

Posted - Jan 14 2024 :  04:17:16  Show Profile  Reply
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
Go to Top of Page

PeterPanino

934 Posts

Posted - Jan 14 2024 :  14:15:06  Show Profile  Reply
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.
Go to Top of Page

xequte

38654 Posts

Posted - Jan 16 2024 :  18:50:29  Show Profile  Reply
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
Go to Top of Page

PeterPanino

934 Posts

Posted - Jan 17 2024 :  01:29:46  Show Profile  Reply
The attached project TransformImageToLayer2.zip clearly demonstrates how it works:

https://app.screencast.com/y8clbqdOnYdQS
Go to Top of Page

xequte

38654 Posts

Posted - Jan 19 2024 :  21:34:56  Show Profile  Reply
Hi Peter

Yes, the code in the demo looks OK.

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