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
 Replace background image by Image-Layer Image?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

934 Posts

Posted - Jan 29 2021 :  10:22:05  Show Profile  Reply
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?

PeterPanino

934 Posts

Posted - Jan 29 2021 :  11:49:32  Show Profile  Reply
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;
Go to Top of Page

PeterPanino

934 Posts

Posted - Jan 29 2021 :  14:12:34  Show Profile  Reply
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;
Go to Top of Page

xequte

38682 Posts

Posted - Jan 31 2021 :  18:30:01  Show Profile  Reply
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
Go to Top of Page

PeterPanino

934 Posts

Posted - Feb 01 2021 :  05:57:50  Show Profile  Reply
 
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 );

Go to Top of Page

PeterPanino

934 Posts

Posted - Feb 01 2021 :  10:41:31  Show Profile  Reply
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.
Go to Top of Page

xequte

38682 Posts

Posted - Feb 01 2021 :  19:40:18  Show Profile  Reply
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
Go to Top of Page

PeterPanino

934 Posts

Posted - Feb 02 2021 :  04:34:15  Show Profile  Reply
Yes, this is another possibility. Thanks for the information. I appreciate your support.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: