After loading the .bin in your program, use some pokes to restore the header
I haven't tested that part out yet but it should look something like this:
Code: Select all
Define PNGHeader.s = Chr(137) + "PNG" + Chr(13) + Chr(10) + Chr(26) + Chr(10) ; PNG header
Code: Select all
EnableExplicit
Global ConfigFile.s = GetPathPart(ProgramFilename()) + "PNG_Header-Stripper_Config.TXT"
Global SourcePath.s, SelectedSource.s
Define.s ImageFile, OutputFile
Define FileSize, *ImageMemory, *StrippedMemory
;******************************************************
; Procedures
;******************************************************
Procedure EndProgram()
; Update Config.TXT with the latest source and destination paths
If CreateFile(0, ConfigFile)
; Write SelectedSource if it’s set, otherwise use SourcePath or "0"
If SelectedSource <> ""
WriteStringN(0, SelectedSource)
ElseIf SourcePath <> ""
WriteStringN(0, SourcePath)
Else
WriteStringN(0, "0")
EndIf
Else
ConsoleColor(12, 0)
PrintN("Warning: Could not update " + ConfigFile)
EndIf
ConsoleColor(8, 0)
PrintN("")
PrintN("Press RETURN to exit...")
Input()
End
EndProcedure
; Open the console for user interaction
OpenConsole()
; Check if Config.TXT exists, create if not
If FileSize(ConfigFile) = -1
If CreateFile(0, ConfigFile)
WriteStringN(0, "0")
CloseFile(0)
Else
ConsoleColor(12, 0)
PrintN("Error: Could not create " + ConfigFile)
EndProgram()
EndIf
EndIf
; Read Config.TXT
If ReadFile(0, ConfigFile)
SourcePath = ReadString(0)
CloseFile(0)
Else
ConsoleColor(12, 0)
PrintN("Error: Could not read " + ConfigFile)
EndProgram()
EndIf
; Validate source and destination paths
If SourcePath <> "0" And FileSize(SourcePath) <> -2
SourcePath = "0"
EndIf
Define InitialSource.s = ""
If SourcePath <> "0" ; Set initial value from Multi-Folder_Packer_Config.TXT once
InitialSource = SourcePath
EndIf
ConsoleColor(14, 0)
PrintN("PNG Header-Stripper by Carm3D v1.1")
PrintN("")
ConsoleColor(8, 0)
PrintN("This little program will load a PNG image,")
PrintN("strip out the PNG header data, then save")
PrintN("it as a binary file for your Pure Basic")
PrintN("projects. Enjoy!")
PrintN("")
; Open a file requester to select the image
ImageFile = OpenFileRequester("Select a PNG Image", SourcePath, "PNG Files (*.png)|*.png", 0)
If ImageFile <> ""
OutputFile = ImageFile + ".bin" ; Save with .bin extension
; Load the image into memory
If ReadFile(0, ImageFile)
FileSize = Lof(0)
*ImageMemory = AllocateMemory(FileSize)
If *ImageMemory
ReadData(0, *ImageMemory, FileSize)
CloseFile(0)
; Strip the first 8 bytes (PNG header)
*StrippedMemory = *ImageMemory + 8
FileSize - 8
; Save the stripped binary data
If CreateFile(1, OutputFile)
WriteData(1, *StrippedMemory, FileSize)
CloseFile(1)
PrintN("Saved " + OutputFile + " without PNG header.")
Else
PrintN("Error: Could not create output file.")
EndProgram()
EndIf
FreeMemory(*ImageMemory)
; Extract the directory from the full path (excluding the filename)
SelectedSource = GetPathPart(ImageFile)
Else
PrintN("Error: Could not allocate memory.")
EndProgram()
EndIf
Else
PrintN("Error: Could not open " + ImageFile)
EndProgram()
EndIf
Else
PrintN("No file selected. Exiting...")
EndProgram()
EndIf
EndProgram()