__Imagecreate syntax

New to FreeBASIC? Post your questions here.
Post Reply
lucidapogee
Posts: 19
Joined: Mar 06, 2023 2:07
Location: Arizona
Contact:

__Imagecreate syntax

Post by lucidapogee »

I have been looking at documentation and answers to my previous questions, but I am unable to figure this out.

From the documentation at https://www.freebasic.net/wiki/KeyPgImagecreate

Code: Select all

'Create a 64x64 pixel image with a darkish green background.
Dim image As Any Ptr = ImageCreate( 64, 64, RGB(0, 128, 0) )
How do I define an image buffer in -lang qb syntax? I thought about defining it in a dll as FB syntax, but I don't understand how to do that either. What would I put in the dll? Does it have to be in a function?

"Not available in the -lang qb dialect unless referenced with the alias __Imagecreate." I see that it's possible, but I haven't been able to make it work.

My goal is to use __imagecreate with bload, put, and __imagedestroy in -lang qb.
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: __Imagecreate syntax

Post by coderJeff »

lucidapogee wrote: Apr 01, 2023 2:07 "Not available in the -lang qb dialect unless referenced with the alias __Imagecreate." I see that it's possible, but I haven't been able to make it work.
What have you tried? We'd be interested to know where you got stuck.

"... unless referenced with the alias __Imagecreate" means use "__Imagecreate".

Code: Select all

#lang "qb"

sub MakeAndSaveImage
	Dim image As Any __Ptr
	image = __ImageCreate( 64, 64, __RGB(0, 128, 0) )

	'' draw on the image created
	for x = 0 to 63 step 5
		line image, (0,0)-(x,63), 15
		line image, (63-x,0)-(63,63), 15
	next

	bsave "tmppic.bmp", image, 64*64*4

	__imagedestroy( image )
end sub

sub LoadAndShowImage
	Dim image As Any __Ptr
	image = __ImageCreate( 64, 64, __RGB(0, 128, 0) )
	bload "tmppic.bmp", image

	'' put the image on the screen
	put (0,0),image,pset
	put (100,0),image,pset
	put (200,100),image,pset
	put (300,300),image,pset

	__imagedestroy( image )
end sub

screen 12, 32

MakeAndSaveImage
print "image saved - press key to continue"
sleep

cls
LoadAndShowImage
sleep
lucidapogee
Posts: 19
Joined: Mar 06, 2023 2:07
Location: Arizona
Contact:

Re: __Imagecreate syntax

Post by lucidapogee »

It appears you answered my question perfectly.

I was stuck on syntax. The docs mention when a command may be aliased with __ for QB syntax, but I don't really see any specific examples such as the one you just shared. Over time it would be great to see more of such examples in Free Basic docs.

This part is pretty much what I was looking for. I need to write this as two lines and with __ on the ptr.

Code: Select all

Dim image As Any __Ptr
image = __ImageCreate( 64, 64, __RGB(0, 128, 0) )
I don't know how long that would have taken me to figure out by trial and error. Thank you!
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: __Imagecreate syntax

Post by coderJeff »

lucidapogee wrote: Apr 01, 2023 7:54 I was stuck on syntax. The docs mention when a command may be aliased with __ for QB syntax, but I don't really see any specific examples such as the one you just shared. Over time it would be great to see more of such examples in Free Basic docs.
There are some examples in the wiki that could be converted to qb dialect syntax that would only require adding '__' as a prefix to the keywords that are in fb (and fblite). I'm not sure how worthwhile that would be?

If you are committed to writing new code in the qb dialect, you may find some practice with syntax (and peculiarities of the qb dialect) by converting some existing examples. If you post the conversions, I'm sure we could find a place to include them in the docs.

My opinion is that most users won't be using qb dialect for writing new code since many fb features are not available in the qb dialect. However the fblite dialect is a little bit like qb dialect and a little bit like fb dialect so you may find that useful to write qb like code with more fb like features. I dunno.
lucidapogee
Posts: 19
Joined: Mar 06, 2023 2:07
Location: Arizona
Contact:

Re: __Imagecreate syntax

Post by lucidapogee »

Some people are visual learners. It will help greatly. These things ARE supported, just not documented well enough.
Post Reply