PDA

View Full Version : Inserting a simple JPEG or BMP into a Canvas



MattW
16-01-2013, 21:41
Hi,

I'm trying to display a 14 digit display (similiar the the 7-segment ones). At first I thought about drawing in the relevant lines to make 'each digit'. i.e. Draw top line, draw side LH line, draw middle line, draw...etc! Get the idea? Here is my designing process...
8084
But this is getting complicated and surely there is an easier way?

How about if I designed each pattern in Adobe Photoshop or even paint (very simple image) - creating a separate image (jpg) for every number required (e.g. 0,1,2,3,4,5,6,7,8,9,etc). When I need to change the number on the canvas then I will just keep replacing the original jpg with the file required when I need the number to change?

Apologies - I'm not a beginner with the BASIC language, but I am a beginner with ThinBasic (used QBasic before!)

Also, how do you check for a key press without stopping program execution...
e.g.

aa:
K$=KEY$
IF K$="Y" THEN PRINT "Hello, you pressed Y"
PRINT "program is still running"
GOTO aa:


Please help, thank you :)

Matt

BTW, already looked at C:\thinBasic\SampleScripts\UI\Canvas\Image_Background\live_image.tbasic (found this in one of the posts) but this seems incredibly long and I don't get what I need to do :confused:

Petr Schreiber
16-01-2013, 22:12
Hi MattW,

you could do what you need with BMP files and Canvas.
The command you need is called Canvas_BitmapRender, it has this syntax:

Canvas_BitmapRender(BitmapFileName [, X1, Y1 [, X2, Y2]])

Parameter 1 is the BMP file name
Parameters 2, 3 is X, Y position of upper left corner on the canvas
Parameters 4, 5 is X, Y position of lower right corner on the canvas

If you want to use transparent color, I suggest to copy the function RenderImageToExistingCanvasWithMaskedColor from the live_image.tBasic script and use it.

The function for non-blocking input is called Canvas_Inkey.

All functions are documented, you can find them in help file under path:
thinBasic Modules > UI (User Interface) > Additional Controls and Functions > Canvas Control

Petr

MattW
16-01-2013, 22:40
Hi MattW,

you could do what you need with BMP files and Canvas.
The command you need is called Canvas_BitmapRender, it has this syntax:

Canvas_BitmapRender(BitmapFileName [, X1, Y1 [, X2, Y2]])

Parameter 1 is the BMP file name
Parameters 2, 3 is X, Y position of upper left corner on the canvas
Parameters 4, 5 is X, Y position of lower right corner on the canvas

If you want to use transparent color, I suggest to copy the function RenderImageToExistingCanvasWithMaskedColor from the live_image.tBasic script and use it.

The function for non-blocking input is called Canvas_Inkey.

All functions are documented, you can find them in help file under path:
thinBasic Modules > UI (User Interface) > Additional Controls and Functions > Canvas Control

Petr

Ok, thanks... I've tried...

Canvas_BitmapRender(test.bmp [, 2, 2 [, 15, 15]])

I have placed the test.bmp into the c:\thinbasic folder, and also in same folder as the *.tbasic file...
8085

No go (error above). Have I missed something?

Matt

MattW
16-01-2013, 22:46
Hi MattW,

All functions are documented, you can find them in help file under path:
thinBasic Modules > UI (User Interface) > Additional Controls and Functions > Canvas Control

Petr

Ah sorry - I missed this part, I will look here also

MattW
17-01-2013, 01:54
Ah sorry - I missed this part, I will look here also

...found this part (but it's a copy of above).

Sorry, I still don't get it...

Canvas_BitmapRender(test.bmp [, 2, 2 [, 15, 15]])

...still brings up the same error.
I don't understand where ThinBasic is looking to find the bmp. I've even tried the full path (eg... c:\myphoto\test.bmp) which also didn't work :(

Matt

Petr Schreiber
17-01-2013, 09:42
Hi!,

the bitmap name is a string parameter, so instead of:

test.bmp

you need to use quotes:

"test.bmp"


Petr

MattW
17-01-2013, 10:16
Hi!,

the bitmap name is a string parameter, so instead of:

test.bmp

you need to use quotes:

"test.bmp"


Petr
Thanks Petr,

It worked, but had to remove all the "[" and "]" (maybe this was just symbolising something and not part of the code itself?)
Canvas_BitmapRender("test.bmp" , 2, 2 , 20, 20)

BTW...
http://www.thinbasic.com/community/showthread.php?9026-ThinBasic-Journal-Issue-1
Delicious....! It even mentions the "ZX SPECTRUM!!!", which is where my coding all began when I was about 10 years old!!

Going into our town centre, going into shops selling the ZX Spectrum and entering code...

10 PRINT "Don't press any key!!! Or else...!"
20 IF INKEY$="" THEN GOTO 10
30 PRINT "TOLD YOU SO"
40 LET L=USR(4380)
(hehe can't remember line 40 exactly, but it froze the PC!! Now that was naughty!!:D)


By the way, whats the ALTERNATIVE to using the GOTO command. I've seen lots of posts on this, I know TB doesn't use this, but I didn't reach a conclusion on what I should use instead. I know that I have to learn a new way of coding, but this is all kind of new to me.
I read that I have to use a function, but not sure how to structure this with the GOTO command in mind...?

Matt

MattW
17-01-2013, 12:50
Thanks Petr,

By the way, whats the ALTERNATIVE to using the GOTO command. I've seen lots of posts on this, I know TB doesn't use this, but I didn't reach a conclusion on what I should use instead. I know that I have to learn a new way of coding, but this is all kind of new to me.
I read that I have to use a function, but not sure how to structure this with the GOTO command in mind...?

Matt

I'll put this in a new post :)

Petr Schreiber
17-01-2013, 15:46
I am happy you liked the Journal articles. The Journal itself transformed into online articles published here (http://www.thinbasic.com/community/content.php).



It worked, but had to remove all the "[" and "]" (maybe this was just symbolising something and not part of the code itself?)


The [, ] mean that the thing inside them is optional. For example, with this:


Canvas_BitmapRender(BitmapFileName [, X1, Y1 [, X2, Y2]])


It means you can use it in 3 ways:


Canvas_BitmapRender("test.bmp") ' -- Renders image at default location, with default size

Canvas_BitmapRender("test.bmp", 10, 10) ' -- Renders image at (10, 10), with default size

Canvas_BitmapRender("test.bmp", 10, 10, 50, 50) ' -- Renders image at (10, 10), stretched from there to (50, 50)



Petr