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
 Replace background image by Image-Layer Image?

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 29 2021 : 10:22:05
I have modified this ImageEn demo:

\Demos\LayerEditing\DragDropLayers

See attached demo project:

attach/PeterPanino/202112910542_LayersDragDrop.zip
141.91 KB

I added a button that should replace the current background image with the currently selected image-layer. The button's click-handler has this code:

procedure TMainForm.Button1Click(Sender: TObject);
begin
  ImageEnView1.Assign(ImageEnView1.Layers[ImageEnView1.LayersCurrent].Bitmap);
  ImageEnView1.Update;
end;


1. First load a background-image with the original "Load Background..." button.

2. Then create an image-layer by dragging from one of the left-side boxes to the background-image.

3. Then click my added button "Replace background image by Layer Image":

If you have dragged a text from the top box with the sample texts or from the box with the shapes then it works: The background-image is being replaced by the layer-image.

But if you have created the layer by dragging an image from the bottom box with the image templates then it does NOT work! It seems that the background image cannot be replaced with the layer-image if the layer was created by an image template.

Why this does not work? How can I replace the background image with the Layer Image created from a template image?
7   L A T E S T    R E P L I E S    (Newest First)
PeterPanino Posted - Feb 02 2021 : 04:34:15
Yes, this is another possibility. Thanks for the information. I appreciate your support.
xequte Posted - Feb 01 2021 : 19:40:18
Sorry, you are correct. I forgot that we made Assign() to be layer aware.

That is why this code fails:

procedure TMainForm.Button1Click(Sender: TObject);
var
  iebmp: TIEBitmap;
begin
  iebmp := TIEBitmap.Create;
  try
    ImageEnView1.Layers[ImageEnView1.LayersCurrent].CopyToBitmap(iebmp);
    ImageEnView1.Assign(iebmp); 
  finally
    iebmp.Free;
  end;
  ImageEnView1.Update;
end;


Because the call ImageEnView1.Assign(iebmp) is just assigning the bitmap back to ImageEnView1.LayersCurrent.Bitmap.

You need to set LayersCurrent to the background layer (0) before the assignment.

So this works:

var
  iebmp: TIEBitmap;
begin
  iebmp := TIEBitmap.Create;
  try
    ImageEnView1.CurrentLayer.CopyToBitmap(iebmp);
    ImageEnView1.LayersCurrent := 0;
    ImageEnView1.Assign(iebmp);
  finally
    iebmp.Free;
  end;
end;


As does this:

  ImageEnView1.Layers[0].Bitmap.Assign( ImageEnView1.CurrentLayer.Bitmap );
  ImageEnView1.Update();


Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Feb 01 2021 : 10:41:31
This seems to be a LOGICAL SHORT CIRCUIT:

 
ImageEnView1.Assign( ImageEnView1.CurrentLayer.Bitmap );



...because trying to replace the image's bitmap with the bitmap of the layer that is held by the image itself currently does not work.

That's the reason why you need the workaround proposed by me above:

 
procedure TMainForm.Button1Click(Sender: TObject);
var
  iebmp: TIEBitmap;
begin
  iebmp := TIEBitmap.Create;
  try
    ImageEnView1.CurrentLayer.CopyToBitmap(iebmp);
    ImageEnView1.LayersClear(False); // IMPORTANT!!!
    ImageEnView1.IEBitmap.Assign(iebmp);
  finally
    iebmp.Free;
  end;
  ImageEnView1.Update;
end;



...because the existence of a layer prevents the assignment to the image's bitmap by its layer's bitmap. So you need to store the image layer's bitmap in a temporary bitmap and then assign it after you have cleared the layers.
PeterPanino Posted - Feb 01 2021 : 05:57:50
 
So the issue was that they layers were hiding the image you copied to the background?


No, that was not the issue. The issue is that this code simply does not work:

 
procedure TMainForm.Button1Click(Sender: TObject);
begin
  ImageEnView1.Assign( ImageEnView1.CurrentLayer.Bitmap );
  ImageEnView1.LayersClear(False);
end;



Didn't you try out my attached demo? There may be a bug in this code:

 
ImageEnView1.Assign( ImageEnView1.CurrentLayer.Bitmap );

xequte Posted - Jan 31 2021 : 18:30:01
Hi Peter

Sorry, did not have a chance to look at this over the weekend.

So the issue was that they layers were hiding the image you copied to the background?

You should be able to simplify your code to:

procedure TMainForm.Button1Click(Sender: TObject);
begin
  ImageEnView1.Assign( ImageEnView1.CurrentLayer.Bitmap );
  ImageEnView1.LayersClear(False);
end;


Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Jan 29 2021 : 14:12:34
Found a working workaround:

procedure TMainForm.Button1Click(Sender: TObject);
var
  iebmp: TIEBitmap;
begin
  iebmp := TIEBitmap.Create;
  try
    ImageEnView1.CurrentLayer.CopyToBitmap(iebmp);
    ImageEnView1.LayersClear(False); // IMPORTANT!!!
    ImageEnView1.IEBitmap.Assign(iebmp);
  finally
    iebmp.Free;
  end;
  ImageEnView1.Update;
end;
PeterPanino Posted - Jan 29 2021 : 11:49:32
Even this workaround does not work:

procedure TMainForm.Button1Click(Sender: TObject);
var
  iebmp: TIEBitmap;
begin
  iebmp := TIEBitmap.Create;
  try
    ImageEnView1.Layers[ImageEnView1.LayersCurrent].CopyToBitmap(iebmp);
    ImageEnView1.Assign(iebmp); 
  finally
    iebmp.Free;
  end;
  ImageEnView1.Update;
end;