Confusing statements in $GrabImage

Found an issue in the documentation ? Please report it here !

Moderator: Documentation Editors

es_91
Enthusiast
Enthusiast
Posts: 298
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

Confusing statements in $GrabImage

Post by es_91 »

GrabImage copies a section from a source image into target image. The target can be #pb_any, but not a previously dynamically created image...

The help states:
#Image2 A number to identify the new image. #PB_Any can be specified to auto-generate this number.

Note: The number of an existing image created using #PB_Any can not be used as the target image. Instead, the existing image must be freed and a new number generated by passing #PB_Any here.
What shall thelast sentence mean? That i need to free an image to reuse it's system handle? Is not necessary when using #PB_Any.

:?
:mrgreen:
User avatar
Mijikai
Addict
Addict
Posts: 1517
Joined: Sun Sep 11, 2016 2:17 pm

Re: Confusing statements in $GrabImage

Post by Mijikai »

If you already have created a image using #PB_Any, you can not pass its number as argument for #Image2 unless you release it before.
So #Image2 can be a number (that is available) or #PB_Any.
User avatar
Demivec
Addict
Addict
Posts: 4257
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Confusing statements in $GrabImage

Post by Demivec »

es_91 wrote: Wed Jun 04, 2025 7:54 pm GrabImage copies a section from a source image into target image. The target can be #pb_any, but not a previously dynamically created image...

The help states:
#Image2 A number to identify the new image. #PB_Any can be specified to auto-generate this number.

Note: The number of an existing image created using #PB_Any can not be used as the target image. Instead, the existing image must be freed and a new number generated by passing #PB_Any here.
What shall thelast sentence mean? That i need to free an image to reuse it's system handle? Is not necessary when using #PB_Any.
There are only two choices for the target image number.

Use #image to use (or reuse) a constant image number or instead use #PB_Any to create a dynamic image number.

If you are reusing an #image constant then PureBasic will free the old image, if it exists, before grabbing a new one.

If you are creating a new dynamic image number with #PB_Any then you will have to remember to free it when you are done with it because you cannot simply reuse the dynamically created image again for the destination of a future grab.
es_91
Enthusiast
Enthusiast
Posts: 298
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

Re: Confusing statements in $GrabImage

Post by es_91 »

Oh, it can't be used again :idea: :mrgreen:

Thanks a lot Demivec :D
:mrgreen:
Post Reply