|
Post by wbtcpip on Jun 16, 2019 0:54:34 GMT 1
Hello, do you a very very simple code to load a PNG into a Picture object or Image OCX?
|
|
webu
Full Member
Posts: 145
|
Post by webu on Jun 24, 2019 22:05:56 GMT 1
Do you found a "very simple code"?
In the GFA-Basic Help for the LoadPicture-Function you can find a example. I used this function also with PNG since years ago, so try it.
|
|
|
Post by scalion on Jun 26, 2019 21:18:52 GMT 1
Hi wbtcpip, Did you find what you are looking for in this post ? : gb32.proboards.com/thread/139/demo-loading-png-pictureIf this is not the case can you specify what you mean by "simple" ? Maybe GdiPlus is the solution for you, in this case you insert a libray link on the top of your program $Library "C:\Program Files (x86)\GFABASIC32 V2.5\Include\gdip.inc.lg32" You have a function GdipCreateBitmapFromFile() who support PNG (and others) but i dont know how she work.
|
|
|
Post by scalion on Jun 28, 2019 9:41:33 GMT 1
I written specially for you this library, hope that help you. Copy it in your library folder or in your program folder, how you want, and write the corresponding $Library statement. Note that you dont have to copy the Zlib32.dll, if is not present he's automatically created when you call PictureFromPng .
Example how to use :
$Library "PictureFromPng" Global MyPic As Picture, PngFile As String FullW 1 : AutoRedraw = 1 : PrintScroll = 1 FileSelect "*.png", "", PngFile PictureFromPng PngFile, MyPic Do AlphaPaintPicture MyPic, MouseX, MouseY Sleep : Loop Until Me Is Nothing Set MyPic = Nothing Have a good day
|
|
|
Post by scalion on Jul 2, 2019 8:20:23 GMT 1
I try using Gdip but i dont know why i can't have result with the GdipLoadImageFromFile() My code (sorry i accidentaly put a new code who is work, that's to dragonjim, lol):
$Library "C:\Program Files (x86)\GFABASIC32 V2.5\Include\gdip.inc.lg32" FullW 1 Global String Filename FileSelect "*.bmp", "", Filename If Exist(Filename) Void ConvertBmpFileToPngFile(Filename , "c:\temp\test.png" ) Else If Len(Filename) > 0 Message "Whare are you ?" EndIf CloseW 1 Function ConvertBmpFileToPngFile(Source$, Target$) Local Long img%, Token%, Test%, MyGraphic, Vnull Local SU As GdiplusStartupInput Local CLSID As GUID Local String SCLSID ' in windef.inc.g32 we have : ' Type GUID ' D1 As Int ' D2 As Card ' D3 As Card ' D4(7) As Byte ' EndType ' ' in gdip.inc.g32 we have only the decoder : ' DEFINE_GUID(ImageFormatPNG, 0xb96b3caf,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e); ' i have modified gdip.inc.g32 and rebuilt the lg32 (after removing it in file explorer) ' i change the "as any" to "by val ... as long" for the last param of GdipSaveImageToFile() ' according to the documentation of the Declare command. ' The "As Any" type is not supported in GFA-BASIC 32 (with reasons) and should be replaced by ByVal … As Long. ' You then pass the address of the variable to the DLL function. ' now my GdipLoadimageFromFile dont work and return the code 3 (out of memory) ' Finally i found this Encoder clsid for PNG on the web: 'const CLSID pngEncoderClsId = { 0x557cf406, 0x1a04, 0x11d3,{ 0x9a,0x73,0x00,0x00,0xf8,0x1e,0xf3,0x2e } }; ' This to LOAD png 'CLSID.D1 = &hb96b3caf 'CLSID.D2 = &h0728 'CLSID.D3 = &h11d3 'CLSID.D4(0) = &h9d 'CLSID.D4(1) = &h7b 'CLSID.D4(2) = &h00 'CLSID.D4(3) = &h00 'CLSID.D4(4) = &hf8 'CLSID.D4(5) = &h1e 'CLSID.D4(6) = &hf3 'CLSID.D4(7) = &h2e ' This to save... CLSID.D1 = 0x557cf406 CLSID.D2 = 0x1a04 CLSID.D3 = 0x11d3 CLSID.D4(0) = &h9a CLSID.D4(1) = &h73 CLSID.D4(2) = &h00 CLSID.D4(3) = &h00 CLSID.D4(4) = &hf8 CLSID.D4(5) = &h1e CLSID.D4(6) = &hf3 CLSID.D4(7) = &h2e MemBFill V:SU, SizeOf(SU), 0 SU.GdiplusVersion = 1 SU.SuppressBackgroundThread = False SU.SuppressExternalCodecs = False Test = GdiplusStartup(Token, SU, Null) If Test Message "Dont work now" Return Test & " " & GdipStatusText(Test) Exit Function EndIf Test = GdipCreateFromHDC(Me.hDC, MyGraphic) If Test Message "No graphic.... pffff." EndIf Test = GdipLoadImageFromFile(StrW(Source), img) If Test Message "not again " & Test & " " & GdipStatusText(Test) GdiplusShutdown(Token) Return Test EndIf For Test = 0 To 100 Void GdipDrawImageI(MyGraphic, img, Test * 3, Test * 2) Next Test Pause 10 Test = GdipSaveImageToFile(img, StrW(Target), CLSID, Null) GdipDisposeImage(img) GdiplusShutdown(Token) If Test <> 0 Message "not saved. no, no and no" & Test & " " & GdipStatusText(Test) EndIf Return Test End Function Function GdipStatusText(StatusNumber%) As String Select StatusNumber Case 0 : Return "StatusOk" Case 1 : Return "StatusGenericError" Case 2 : Return "StatusInvalidParameter" Case 3 : Return "StatusOutOfMemory" Case 4 : Return "StatusObjectBusy" Case 5 : Return "StatusInsufficientBuffer" Case 6 : Return "StatusNotImplemented" Case 7 : Return "StatusWin32Error" Case 8 : Return "StatusWrongState" Case 9 : Return "StatusAborted" Case 10 : Return "StatusFileNotFound" Case 11 : Return "StatusValueOverflow" Case 12 : Return "StatusAccessDenied" Case 13 : Return "StatusUnknownImageFormat" Case 14 : Return "StatusFontFamilyNotFound" Case 15 : Return "StatusFontStyleNotFound" Case 16 : Return "StatusNotTrueTypeFont" Case 17 : Return "StatusUnsupportedGdiplusVersion" Case 18 : Return "StatusGdiplusNotInitialized" Case 19 : Return "StatusPropertyNotFound" Case 20 : Return "StatusPropertyNotSupported" Case 21 : Return "ProfileNotFound" EndSelect Return "Unknow" EndFunc Function StrW(vnt As Variant, Optional skip?) As String // v3 // Acknowledgements to Sjouke Hamstra Dim a$, BSTR As Register Long : BSTR = {V:vnt + 8} a$ = StrPeek(BSTR, {BSTR - 4}) : If Not skip? Then a$ = a$ & Chr(0) Return a$ EndFunction
|
|
|
Post by wbtcpip on Jul 2, 2019 14:37:33 GMT 1
thank you scalion. i know your sample code about PNG at gb32.proboards.com/thread/139/demo-loading-png-picture but i was looking for a piece code more short and without effects. something really basic just to display pgn in a picturebox. now i try your lib i will tell you if it works here.
|
|
|
Post by wbtcpip on Jul 2, 2019 21:04:26 GMT 1
your PictureFromPng.lg32 works fine, thank you!
|
|
|
Post by scalion on Jul 3, 2019 12:49:34 GMT 1
|
|
|
Post by dragonjim on Jul 3, 2019 21:31:37 GMT 1
Hi Scalion, Good work on the PNG load and save libraries. Just to answer your question on one of the reasons why your GDI+ example didn't work: GDI+ APIs take Unicode strings, not ASCII. You can use Sjouke Hamstra's function below to convert ASCII to Unicode:
Function StrW(vnt As Variant, Optional skip?) As String // v3 // Acknowledgements to Sjouke Hamstra Dim a$, BSTR As Register Long : BSTR = {V:vnt + 8} a$ = StrPeek(BSTR, {BSTR - 4}) : If Not skip? Then a$ = a$ & Chr(0) Return a$ EndFunction As to why it will not save as a PNG, I have yet to work this out although if you get error code 7 it is because you do not have a C:\Temp folder (actually 7 = Win32Error); I keep getting error code 10 which is, oddly enough, File Not Found (regardless of whether a file of that name actually exists).
|
|
|
Post by scalion on Jul 4, 2019 14:13:37 GMT 1
OMG !!! Thank you dragonjim you are my god !! The error filenotfound come of the clsid who is the decoder clsid and not the encoder. I found on the web the good clsid ! We can save also with GdiPlus now ! NB : Tif,Gif,Jpg and more are supported by GDIPlus , just we need to found the good CLSID !!! not very difficult
look at this code and try it :
$Library "C:\Program Files (x86)\GFABASIC32 V2.5\Include\gdip.inc.lg32" FullW 1 Global String Filename FileSelect "*.bmp", "", Filename If Exist(Filename) Void ConvertBmpFileToPngFile(Filename , "c:\temp\test.png" ) Else If Len(Filename) > 0 Message "Whare are you ?" EndIf CloseW 1 Function ConvertBmpFileToPngFile(Source$, Target$) Local Long img%, Token%, Test%, MyGraphic, Vnull Local SU As GdiplusStartupInput Local CLSID As GUID Local String SCLSID ' in windef.inc.g32 we have : ' Type GUID ' D1 As Int ' D2 As Card ' D3 As Card ' D4(7) As Byte ' EndType ' ' in gdip.inc.g32 we have only the decoder : ' DEFINE_GUID(ImageFormatPNG, 0xb96b3caf,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e); ' i have modified gdip.inc.g32 and rebuilt the lg32 (after removing it in file explorer) ' i change the "as any" to "by val ... as long" for the last param of GdipSaveImageToFile() ' according to the documentation of the Declare command. ' The "As Any" type is not supported in GFA-BASIC 32 (with reasons) and should be replaced by ByVal … As Long. ' You then pass the address of the variable to the DLL function. ' now my GdipLoadimageFromFile dont work and return the code 3 (out of memory) ' Finally i found this Encoder clsid for PNG on the web: 'const CLSID pngEncoderClsId = { 0x557cf406, 0x1a04, 0x11d3,{ 0x9a,0x73,0x00,0x00,0xf8,0x1e,0xf3,0x2e } }; ' This to LOAD png 'CLSID.D1 = &hb96b3caf 'CLSID.D2 = &h0728 'CLSID.D3 = &h11d3 'CLSID.D4(0) = &h9d 'CLSID.D4(1) = &h7b 'CLSID.D4(2) = &h00 'CLSID.D4(3) = &h00 'CLSID.D4(4) = &hf8 'CLSID.D4(5) = &h1e 'CLSID.D4(6) = &hf3 'CLSID.D4(7) = &h2e ' This to save... CLSID.D1 = 0x557cf406 CLSID.D2 = 0x1a04 CLSID.D3 = 0x11d3 CLSID.D4(0) = &h9a CLSID.D4(1) = &h73 CLSID.D4(2) = &h00 CLSID.D4(3) = &h00 CLSID.D4(4) = &hf8 CLSID.D4(5) = &h1e CLSID.D4(6) = &hf3 CLSID.D4(7) = &h2e MemBFill V:SU, SizeOf(SU), 0 SU.GdiplusVersion = 1 SU.SuppressBackgroundThread = False SU.SuppressExternalCodecs = False Test = GdiplusStartup(Token, SU, Null) If Test Message "Dont work now" Return Test & " " & GdipStatusText(Test) Exit Function EndIf Test = GdipCreateFromHDC(Me.hDC, MyGraphic) If Test Message "No graphic.... pffff." EndIf Test = GdipLoadImageFromFile(StrW(Source), img) If Test Message "not again " & Test & " " & GdipStatusText(Test) GdiplusShutdown(Token) Return Test EndIf For Test = 0 To 100 Void GdipDrawImageI(MyGraphic, img, Test * 3, Test * 2) Next Test Pause 10 Test = GdipSaveImageToFile(img, StrW(Target), CLSID, Null) GdipDisposeImage(img) GdiplusShutdown(Token) If Test <> 0 Message "not saved. no, no and no" & Test & " " & GdipStatusText(Test) EndIf Return Test End Function Function GdipStatusText(StatusNumber%) As String Select StatusNumber Case 0 : Return "StatusOk" Case 1 : Return "StatusGenericError" Case 2 : Return "StatusInvalidParameter" Case 3 : Return "StatusOutOfMemory" Case 4 : Return "StatusObjectBusy" Case 5 : Return "StatusInsufficientBuffer" Case 6 : Return "StatusNotImplemented" Case 7 : Return "StatusWin32Error" Case 8 : Return "StatusWrongState" Case 9 : Return "StatusAborted" Case 10 : Return "StatusFileNotFound" Case 11 : Return "StatusValueOverflow" Case 12 : Return "StatusAccessDenied" Case 13 : Return "StatusUnknownImageFormat" Case 14 : Return "StatusFontFamilyNotFound" Case 15 : Return "StatusFontStyleNotFound" Case 16 : Return "StatusNotTrueTypeFont" Case 17 : Return "StatusUnsupportedGdiplusVersion" Case 18 : Return "StatusGdiplusNotInitialized" Case 19 : Return "StatusPropertyNotFound" Case 20 : Return "StatusPropertyNotSupported" Case 21 : Return "ProfileNotFound" EndSelect Return "Unknow" EndFunc Function StrW(vnt As Variant, Optional skip?) As String // v3 // Acknowledgements to Sjouke Hamstra Dim a$, BSTR As Register Long : BSTR = {V:vnt + 8} a$ = StrPeek(BSTR, {BSTR - 4}) : If Not skip? Then a$ = a$ & Chr(0) Return a$ EndFunction
Have a good day !
|
|
|
Post by wbtcpip on Jul 6, 2019 0:12:43 GMT 1
Hi scalion i see you are very good at graphic code. Could you pelase help me with this? Attached there is a video player example. I would like to display a transparent png over the video that is playing (like the logo in a tv station), do you think it's possible?
and also i would like to display text over the video with transparent background .... do you have any clue on how to do it?
thank you
|
|
|
Post by scalion on Jul 6, 2019 9:18:00 GMT 1
Hi wbtcpip, thank's for the flower. I have installed codec and try your program that's work very good. Well now i will try to draw png and text on video, see you.
Update 08/07/2019 : I have a way to search : I think you must use Void BASS_Mixer_ChannelSetSync(basshandle, BASS_SYNC_STALL, 0, ProcAddr(ShowMyItems), 1) just after the Void BASS_ChannelSetAttribute statement
with a sub like this :
Sub ShowMyItems() Naked // here the code to show text or png. EndSub
But now i search what the code must do. i think there is a function to get the stream data in the good order. Dont forget the Naked statement else crash is not far.
Hope that help you, In the meantime I will continue to search.
|
|
|
Post by dragonjim on Jul 8, 2019 22:07:54 GMT 1
Hi Scalion, Glad I was of some assistance in helping you found the answer to your problem with GDI+ saving PNG files. Keep up the good work. Have you considered making creating a library function to load and save different functions using GDI+?
|
|
|
Post by wbtcpip on Jul 8, 2019 23:30:46 GMT 1
Update 08/07/2019 :I have a way to search : I think you must use Void BASS_Mixer_ChannelSetSync(basshandle, BASS_SYNC_STALL, 0, ProcAddr(ShowMyItems), 1) just after the Void BASS_ChannelSetAttribute statement
with a sub like this :
Sub ShowMyItems() Naked // here the code to show text or png. EndSub
But now i search what the code must do. i think there is a function to get the stream data in the good order. Dont forget the Naked statement else crash is not far.
Hope that help you, In the meantime I will continue to search.
Thank you scalion, yes i know very weel all the bass library functions. the problem for me is that i don't have transparency with title and images. For exemple for the song title and the tv logo i use another image ocx but as you can see i don't have transparency over the video.
|
|
|
Post by wbtcpip on Jul 9, 2019 10:57:54 GMT 1
thank you i'll give it a try tonight
|
|
|
Post by wbtcpip on Jul 9, 2019 23:23:53 GMT 1
HI JMM, you code works very well. thank you
|
|
|
Post by wbtcpip on Jul 10, 2019 20:23:38 GMT 1
i was able to create transparent logo and titles over the video.
thank you!
|
|
|
Post by scalion on Jul 22, 2019 12:48:53 GMT 1
Hi Scalion, Glad I was of some assistance in helping you found the answer to your problem with GDI+ saving PNG files. Keep up the good work. Have you considered making creating a library function to load and save different functions using GDI+? Hi DragonJim, yes of course that's a good idea. I will write a library to have a simple Load and Save who's support all graphics format. I will create a thread when it's finished.
|
|
|
Post by wbtcpip on Aug 1, 2019 12:52:59 GMT 1
Local hwnd As Long = frm.hWnd Local Attrib As Long = GetWindowLong(hwnd, GWL_EXSTYLE) ~SetWindowLong(hwnd, GWL_EXSTYLE, Attrib Or WS_EX_LAYERED) ~SetLayeredWindowAttributes(hwnd, KeyColor, Transparency_Byte, LWA_ALPHA Or LWA_COLORKEY)
Hi JMM, how i can do the opposite? i mean i have enabled the WS_EX_LAYERED to a form and now i want to disable it.
|
|
|
Post by wbtcpip on Aug 2, 2019 12:41:39 GMT 1
Thank you JMM, my problem is that i have to remove the WS_EX_LAYERED from the window styles because the window cannot be correctly captured by OBS Broadcaster or winMix when this flag is enabled.
They say to do this: // Remove WS_EX_LAYERED from the window styles SetWindowLong(hChildWnd,GWL_EXSTYLE, GetWindowLong(hChildWnd, GWL_EXSTYLE) & ~WS_EX_LAYERED); RedrawWindow(hChildWnd,NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
but i don't know how to translate ~WS_EX_LAYERED in GB32?
|
|
|
Post by wbtcpip on Aug 2, 2019 13:05:36 GMT 1
ok i solved like this:
Local Attrib As Long = GetWindowLong(hwnd, GWL_EXSTYLE) If (Attrib And WS_EX_LAYERED) then ~SetWindowLong(hwnd, GWL_EXSTYLE, Attrib - WS_EX_LAYERED)
|
|