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
 SetExternalBitmap and Layers
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

egrobler

42 Posts

Posted - Sep 24 2012 :  07:22:13  Show Profile  Reply
Hi

How can I update a layer when I attach a bitmap?

EcImageEnVect1.SetExternalBitmap(EcImageEnVect2.IEBitmap);

EcImageEnVect1.IO.LoadFromFile('background.jpg');
EcImageEnVect1.LayersAdd;
EcImageEnVect1.IO.LoadFromFile('layer.png');

EcImageEnVect2.Update; //Only background is visible on the second image

Best Regards
Eric

w2m

USA
1990 Posts

Posted - Sep 24 2012 :  08:00:00  Show Profile  Reply
Do not use SetExternalBitmap. Instead use a ImageEnView for the preview and set AutoShrink to true. Then do this:
var
iMS: TMemoryStream;
begin
  iMS := TMemoryStream.Create;
  try
    ImageEnView1.LayersSaveToStream(iMS);
    iMS.Position := 0;
    Preview1.LayersLoadFromStream(iMS);
    Preview1.Update;
  finally
    iMS.Free;
  end;
end;

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

egrobler

42 Posts

Posted - Sep 24 2012 :  08:15:39  Show Profile  Reply
Hi William,

I get an Invalid ZStream operation error when trying to save to the stream.
iMS := TMemoryStream.Create;
  try
    ImageEnVect1.IO.LoadFromFile('background.jpg');
    ImageEnVect1.LayersAdd;
    ImageEnVect1.IO.LoadFromFile('layer.png');

    ImageEnVect1.LayersSaveToStream(iMS); //Invalid ZStream operation
    iMS.Position := 0;

    ImageEnVect2.LayersLoadFromStream(iMS);
    ImageEnVect2.Update;
  finally
    iMS.Free;
  end;
Go to Top of Page

w2m

USA
1990 Posts

Posted - Sep 24 2012 :  09:44:41  Show Profile  Reply
Where are you caling this?

Try this:

Open the ...Annotations\Vectorial Demo in the samples folder.
Add a button to the properties scrollbox located on the right side of the main form. Add a ImageEnView to Panel2 located on the left side of the main form. Set the AutoShrink property of the ImageEnView2 to true (ImageEnView2.AutoShrink := True). Then add the following code:
procedure TMainForm.LoadLayers1Click(Sender: TObject);
var
  iMS: TMemoryStream;
  iLayer: integer;
begin
  if OpenImageEnDialog1.Execute then
  begin
    ImageEnVect1.IO.LoadFromFile(OpenImageEnDialog1.FileName);
    ImageEnVect1.LayersSync := False;
    ImageEnVect1.CurrentLayer.VisibleBox := True;
    ImageEnVect1.CurrentLayer.Selectable := True;
    ImageEnVect1.LayersDrawBox := True;
  end;
  iLayer := ImageEnVect1.LayersAdd;
  if OpenImageEnDialog1.Execute then
    ImageEnVect1.IO.LoadFromFile(OpenImageEnDialog1.FileName);
    iMS := TMemoryStream.Create;
    try
      ImageEnVect1.LayersSaveToStream(iMS);
      iMS.Position := 0;
      ImageEnView2.LayersLoadFromStream(iMS);
      ImageEnView2.Update;
    finally
      iMS.Free;
    end;
  ImageEnVect1.LayersCurrent := iLayer;
  ImageEnVect1.MouseInteract := [miMoveLayers, miResizeLayers];
end;

procedure TMainForm.ImageEnVect1LayerNotify(Sender: TObject; layer: Integer; event: TIELayerEvent);
var
  iMS: TMemoryStream;
begin
  // If moving or resizing a layer update the preview ImageEnView
  if (event = ielMoving) or (event = ielResized) then
  begin
    iMS := TMemoryStream.Create;
    try
      ImageEnVect1.LayersSaveToStream(iMS);
      iMS.Position := 0;
      ImageEnView2.LayersLoadFromStream(iMS);
      ImageEnView2.Update;
    finally
      iMS.Free;
    end;
  end;
end;


Click the button then select a layer with the mouse and move it around. All the layers should appear in the ImageEnView (preview) and the layers should be updated when you move the layer in ImageEnVect.

This works with no exceptions or errors here. I have no idea why you get an exception.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: