Lazarus

Programming => Graphics => Graphics and Multimedia => BGRABitmap and LazPaint => Topic started by: pixelink on August 12, 2019, 06:43:52 pm

Title: Replace or Free Previously Assigned Image
Post by: pixelink on August 12, 2019, 06:43:52 pm
Okay... everything is working so far.
Next issue....

How do replace one image with another and then assign it again.
FYI... I may have multiple layered images on the control before putting altogether for final output.

Example, user has choice of two images. They select the 1st, it is assigned and displayed.
But, then they decide to use the second one.
I need to remove the 1st and re-assign the second

I am trying to free "theBMP" but of course I get a SIG error.

What do you suggest?

 
Code: Pascal  [Select][+][-]
  1.  
  2.   ...
  3.   //theBMP is already assigned and displayed on the 1st image (Style_01)
  4.   ...
  5.  
  6.   //load 2nd image
  7.   TheImage1:= TBGRABitmap.Create(Style_02.Picture.Bitmap);
  8.   theBMP.Free;
  9.   theBMP.PutImage(0, 0, TheImage1, dmDrawWithTransparency );
  10.  
Title: Re: Replace or Free Previously Assigned Image
Post by: pixelink on August 12, 2019, 06:47:54 pm
Also, with LAZPaint you have layers.
I may want to work with Layers, but I wouldn't want the user to use the layers in the GUI.


Where are your docs for this?
Title: Re: Replace or Free Previously Assigned Image
Post by: pixelink on August 12, 2019, 06:54:19 pm

 
Code: Pascal  [Select][+][-]
  1.  
  2.   ...
  3.   //theBMP is already assigned and displayed on the 1st image (Style_01)
  4.   ...
  5.  
  6.   //load 2nd image
  7.   TheImage1:= TBGRABitmap.Create(Style_02.Picture.Bitmap);
  8.   theBMP.Free;
  9.   theBMP.PutImage(0, 0, TheImage1, dmDrawWithTransparency );
  10.  

Fixed it.
I put "theBMP.Free" line above my Image1....line

I would still like to know about the layers
Title: Re: Replace or Free Previously Assigned Image
Post by: winni on August 12, 2019, 11:17:41 pm
Hi!

A lot of your question is answered in the BGRA tutorial:

https://wiki.freepascal.org/BGRABitmap_tutorial (https://wiki.freepascal.org/BGRABitmap_tutorial)

Have a nice day

Winni
Title: Re: Replace or Free Previously Assigned Image
Post by: pixelink on August 13, 2019, 02:19:29 pm
Hi!

A lot of your question is answered in the BGRA tutorial:

https://wiki.freepascal.org/BGRABitmap_tutorial (https://wiki.freepascal.org/BGRABitmap_tutorial)

Have a nice day

Winni

I have read these. Where do you think I learned the basics from?... these docs.
But, the tutorials don't cover some of my issues when things don't work right.
Isn't that why this forum is here?


Title: Re: Replace or Free Previously Assigned Image
Post by: circular on August 13, 2019, 09:28:34 pm
No worries you can ask questions here.

If you want to select an image and you are not going to change it, you could simply copy the address of the object:
Code: Delphi  [Select][+][-]
  1. theBMP := TheImage1;

But if you free TheImage1, you need to think about making sure theBMP will not be used anymore. The simpler would be to set theBMP to nil if it was set to TheImage1, and when using theBMP, to check if it is not nil.
Title: Re: Replace or Free Previously Assigned Image
Post by: pixelink on August 14, 2019, 01:34:44 am
No worries you can ask questions here.

If you want to select an image and you are not going to change it, you could simply copy the address of the object:
Code: Delphi  [Select][+][-]
  1. theBMP := TheImage1;

But if you free TheImage1, you need to think about making sure theBMP will not be used anymore. The simpler would be to set theBMP to nil if it was set to TheImage1, and when using theBMP, to check if it is not nil.


OkAY... THANKS
TinyPortal © 2005-2018