Page 1 of 1

Confusing statements in $GrabImage

Posted: Wed Jun 04, 2025 7:54 pm
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.

:?

Re: Confusing statements in $GrabImage

Posted: Wed Jun 04, 2025 8:18 pm
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.

Re: Confusing statements in $GrabImage

Posted: Wed Jun 04, 2025 10:38 pm
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.

Re: Confusing statements in $GrabImage

Posted: Thu Jun 05, 2025 12:27 am
by es_91
Oh, it can't be used again :idea: :mrgreen:

Thanks a lot Demivec :D