Page 1 of 1
DecodeImage for EncodeImage
Posted: Tue Feb 23, 2016 7:47 am
by tj1010
Since this doesn't work and there is a EncodeImage function that's not actually useful for anything practical.
Code: Select all
InitNetwork()
*buffer=ReceiveHTTPMemory("http://www.purebasic.fr/english/styles/subsilverPlus/imageset/purebasic_logo.png")
Debug CatchImage(0,*buffer,MemorySize(*buffer))
FreeMemory(*buffer)
Game server stored profile avatars is one use for it. Without having to build and manage a tmp cache and loading.
Re: DecodeImage for EncodeImage
Posted: Tue Feb 23, 2016 8:34 am
by wilbert
Maybe a stupid question but did you add UsePNGImageDecoder() ?
I see no other reason why your code wouldn't work.
Re: DecodeImage for EncodeImage
Posted: Tue Feb 23, 2016 5:18 pm
by Thade
As wilbert said
Code: Select all
UsePNGImageDecoder()
InitNetwork()
WinWidth=800
WinHeight=600
WinTitle.s="Test"
window1= OpenWindow(-1, 4, 4, WinWidth, WinHeight, WinTitle, #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
If window1
Start1=ButtonGadget(#PB_Any, 5, 5, 190, 20,"Start")
Ende1=ButtonGadget(#PB_Any, 405, 5, 190, 20,"Ende")
Aktuell1=StringGadget(#PB_Any, 5, 60, WinWidth-20,20,"")
Quit = 0
Repeat
EventID = WindowEvent()
If EventID=#PB_Event_Gadget
GadgetNumber=EventGadget()
Select GadgetNumber
Case Start1
*buffer=ReceiveHTTPMemory("http://www.purebasic.fr/english/styles/prosilver/imageset/pblogobb.png")
If *buffer
img=CatchImage(-1, *buffer)
FreeMemory(*buffer)
If img
img1=ImageGadget(-1, 0, 100, ImageWidth(img), ImageHeight(img), ImageID(img))
SetGadgetText(Aktuell1, Str(img))
EndIf
EndIf
Case Ende1
Quit=1
EndSelect
Else
Delay(1)
EndIf
If EventID = #PB_Event_CloseWindow
Quit = 1
EndIf
Until Quit = 1
EndIf
End
Re: DecodeImage for EncodeImage
Posted: Tue Feb 23, 2016 8:10 pm
by tj1010
You guys are right it was me just not realizing I didn't include the dependency. It still would be a nice function.
This is especially useful for network stored bitmaps. I store them in Base64 in JSON objects on a game server for one project.
Code: Select all
UsePNGImageDecoder()
If ReadFile(0,"b64.txt");base64 of image in a text file
*buffer=AllocateMemory(Lof(0))
If ReadData(0,*buffer,Lof(0))
CloseFile(0)
*output=AllocateMemory(MemorySize(*buffer)-((MemorySize(*buffer)*25)/100))
Base64Decoder(*buffer,MemorySize(*buffer),*output,MemorySize(*output))
FreeMemory(*buffer)
If CatchImage(0,*output)
FreeMemory(*output)
If OpenWindow(0,0,0,ImageWidth(0),ImageHeight(0),"",#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
ImageGadget(0,0,0,ImageWidth(0),ImageHeight(0),ImageID(0))
Repeat
event=WaitWindowEvent()
Until event=#PB_Event_CloseWindow
EndIf
FreeImage(0)
EndIf
EndIf
EndIf
End
Re: DecodeImage for EncodeImage
Posted: Thu Mar 31, 2016 7:25 pm
by tj1010
After revisiting a project that uses this I realize you have to use SaveImage() to write CreateImage() memory to disk then load back in with ReadData() to encode. The request is still kind of valid. Of course that's without writing API code for each platform.
Re: DecodeImage for EncodeImage
Posted: Thu Mar 31, 2016 7:34 pm
by wilbert
tj1010 wrote:After revisiting a project that uses this I realize you have to use SaveImage() to write CreateImage() memory to disk then load back in with ReadData() to encode.
Can you explain more in detail ? I don't exactly understand the problem.
You can use EncodeImage() to encode an image in memory and if you need it to be Base64, you can use the result of EncodeImage() as input for Base64Encoder() .