lod
New Member
I feel like a true programmer being a BASIC beginner
Posts: 16
|
Post by lod on May 8, 2019 5:30:35 GMT -5
As the subject states clearly I want to know if Liberty Basic can produce other format than bmp ? I need to make a lot of pictures which will only bear a number from 1 to 100. A hundred tag 10x10 with a text. The background should be transparent so it must be some gif or png., I firstly thought at PHP with a form and a loop bu I'm kind of upset with this language and as I have Liberty Basic I want to give it a try. Is this possible to make transparent PNGs in a loop using LB? Thanks
|
|
|
Post by Gordon Rahman on May 8, 2019 9:12:40 GMT -5
Hi lod,
The answer is no ...... but printing a number over a background is easy to do. It only needs the background-mode of that character (or text) to be set off.....
and the making of sprites from such a "simple" bmp picture is easy too.
call SetBkMode GetDC(hwnd(#1)),1 '1=transparent '2=opaque
Sub SetBkMode hDC, flag CallDLL #gdi32, "SetBkMode",hDC As ulong,_ flag As long, RESULT As long End Sub
To be honest this is no novice stuff .... so remember to clear your LB computer memory when closing your program with
call ReleaseDC hwnd(#1),GetDC(hwnd(#1))
Sub ReleaseDC hWnd, hDC CallDLL#user32,"ReleaseDC",hWnd As ulong,_ hDC As long,result As long End Sub
Here is the function GetDC()
Function GetDC(hWnd)
CallDLL #user32, "GetDC",hWnd As ulong,_
GetDC As ulong
End Function
Note that #1 should be the handle-name of your graphic window or graphicbox.
Gordon
|
|
lod
New Member
I feel like a true programmer being a BASIC beginner
Posts: 16
|
Post by lod on May 8, 2019 11:56:02 GMT -5
It looks quite complex.Ulong, Flag... I Don't know how to handle call dll things. I've found the Python Fu under Gimp but then again I lack Python venom in my vein :-)
Actually I should know the Python side AND the Gimp API command to make it. The solution is out there, I can feel it … Thanks for the answer
|
|
|
Post by Rod on May 8, 2019 13:27:52 GMT -5
Would sprites provide a solution? They have transparent backgrounds. Perhaps tell us a bit more about the task in hand.
|
|
|
Post by Gordon Rahman on May 8, 2019 16:37:55 GMT -5
Dear lod,
I'm sorry I sounded grumpy. Please accept my apologies. What are you looking for? You stated: "The background should be transparent so it must be some gif or png."
Could you use parts of my next example?
nomainwin WindowWidth = 800 WindowHeight = 600
open "Writing a number on a darkgreen background" for graphics_nsb as #1 call SetBkMode GetDC(hwnd(#1)),1 '1=transparent '2=opaque
#1 "fill darkgreen" #1 "color yellow" #1 "font courier 16 bold"
#1 "when leftButtonDown [hh]" #1 "setfocus" #1 "trapclose [quit]" wait
[quit] close #1 end
[hh] prompt "What number to display? ";number prompt "Coordinate X = ?";X prompt "coordinate Y = ?";Y
#1 "place ";X;" ";Y #1 "\";number
wait
'--------------------------------------------------
Sub SetBkMode hDC, flag CallDLL #gdi32, "SetBkMode",hDC As ulong,_ flag As long, RESULT As long End Sub
Function GetDC(hWnd) CallDLL #user32, "GetDC",hWnd As ulong,_ GetDC As ulong End Function
Sub ReleaseDC hWnd, hDC CallDLL#user32,"ReleaseDC",hWnd As ulong,_ hDC As long,result As long End Sub
Gordon
|
|
|
Post by Rod on May 9, 2019 3:22:37 GMT -5
John has worked with gifs and .dlls to do image conversion. Perhaps he will tell us a trick or two. However nothing will be simpler than sprites.
search imagemagic on this forum.
|
|
lod
New Member
I feel like a true programmer being a BASIC beginner
Posts: 16
|
Post by lod on May 9, 2019 5:45:32 GMT -5
I gathered the following lines that will do what I said in the Gimp Python. Then there are scripts to save/export in PNG. I've tried the code you have written. It's great and I guess it could be useful anyhow but not yet.My snippet looks easier if you have Gimp 2.8 Thanks again
newimage = gimp.Image(300,300) gimp.Display(newimage) y=0 while y < 100: textlayer=pdb.gimp_text_fontname(newimage,None,0,0,y,-1,True,20, 0,'Sans') textlayer.visible = False y=y+1
I maybe wrong but imagemagic returns Nothing.
I have to search in the thread, author ...?
Is it a keyword for Google ?
|
|
|
Post by tenochtitlanuk on May 9, 2019 6:09:26 GMT -5
I'm not sure what you want these pngs to look like. The following code generates 100 BMP files with the numbers 1 to 100- basically Gordon's code.. ImageMagick will convert the white background ( and within 20% of that), to transparent, one at a time or as a batch. I do this at the command line, but you could do it programmatically and delete the unwanted bmps at the same time. See examples on my LB site at ImageMagick examples in LB nomainwin
WindowWidth = 200 WindowHeight = 100
open "Multiple images" for graphics_nsb as #wg
#wg "trapclose [quit]" call SetBkMode GetDC( hwnd( #wg)), 1 '1=transparent '2=opaque
#wg "down" #wg "fill 254 255 255" #wg "color red" #wg "font 48 bold"
for i =1 to 99 #wg "cls ; fill 254 255 255" #wg "place 35 60 "; Y #wg "\"; right$( " " +str$( i), 3) #wg "flush" #wg "getbmp scr 1 1 160 65" bmpsave "scr", "mult/number" +right$( " " +str$( i), 3) +".bmp" 'convert 66.bmp -fuzz 20% -transparent white 66trans.png next
wait
[quit] close #wg end
'-------------------------------------------------- Sub SetBkMode hDC, flag CallDLL #gdi32, "SetBkMode",hDC As ulong,_ flag As long, RESULT As long End Sub
Function GetDC(hWnd) CallDLL #user32, "GetDC",hWnd As ulong,_ GetDC As ulong End Function
Sub ReleaseDC hWnd, hDC CallDLL#user32,"ReleaseDC",hWnd As ulong,_ hDC As long,result As long End Sub
|
|
|
Post by tenochtitlanuk on May 9, 2019 6:11:43 GMT -5
Note the software is 'ImageMagick' with a 'k'. And yes, GIMP Python should work..
|
|
fwm
Full Member
Posts: 105
|
Post by fwm on May 11, 2019 11:05:33 GMT -5
You could also try Dan Teel's excellent LBGfx dll, which was written specifically for LB. It handles various image types and has a "transbmp" function which allows a background colour to be made transparent. It was written as a replacement/enhancement of the native LB graphicsbox feature. libertybasiccom.proboards.com/thread/98/lbgfx-graphics-box-replacementI can highly recommend this DLL as I am using it heavily in my own software Keith
|
|