Recent

Author Topic: Replace or Free Previously Assigned Image  (Read 1324 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Replace or Free Previously Assigned Image
« 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.  
« Last Edit: August 12, 2019, 06:45:59 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Replace or Free Previously Assigned Image
« Reply #1 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?
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Replace or Free Previously Assigned Image
« Reply #2 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
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Replace or Free Previously Assigned Image
« Reply #3 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

Have a nice day

Winni

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Replace or Free Previously Assigned Image
« Reply #4 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

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?


Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

circular

  • Hero Member
  • *****
  • Posts: 4196
    • Personal webpage
Re: Replace or Free Previously Assigned Image
« Reply #5 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.
Conscience is the debugger of the mind

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Replace or Free Previously Assigned Image
« Reply #6 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
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

 

TinyPortal © 2005-2018