Curiouser and curiouser ...
You might have guessed but I'm new to Linux.
I've incorporated all of your suggestions and it works in Win/OSX but not Linux.
However ...
The image opens OK using Gimp and FireFox and ImageMajick (whatever that is) but the Image Viewer stops with the error.
This is with both Umbuntu and Mint.
Trond wrote:I've written a few simple apps that compile and run as expected on macOS and Windows
...
This same code works perfectly in macOS and Windows
No, it doesn't, it actually works the same under all OSes. The difference lies in how the OSes handle opening a bmp file with a png extension. Because your code saves a bmp file, not a png file. That's why you get the error message "not a png file".
New code:
Code: Select all
SaveImage(buffer, file$, #PB_ImagePlugin_PNG)
Trouble is if I add the '#PB_ImagePlugin_PNG' it doesn't work in Windows, OSX
or Linux ..
Code: Select all
; PNGTesting.pb
Enumeration
; main window
#WINDOW_MAIN
; image buffer
#IMAGE_BUFFER
; image view
#IMAGE_VIEW
EndEnumeration
Procedure ImageSave(Image.l)
Define file$, PathPart$, FilePart$, buffer.l, w.i, h.i
file$ = SaveFileRequester("Save Reticle as PNG", "Image.png", "Images (.png)|*.png", 0)
If file$ > ""
w = GadgetWidth(Image)
h = GadgetHeight(Image)
PathPart$ = GetPathPart(file$)
FilePart$ = GetFilePart(file$, #PB_FileSystem_NoExtension)
file$ = PathPart$ + FilePart$ + ".png"
CreateImage(buffer, w, h)
StartDrawing(ImageOutput(buffer))
DrawImage(GetGadgetAttribute(Image, #PB_Canvas_Image), 0, 0)
FrontColor($0)
DrawingMode(#PB_2DDrawing_Outlined)
Box(0, 0, w, h)
StopDrawing()
If SaveImage(buffer, file$, #PB_ImagePlugin_PNG)
Debug "imageSave OK ("+ FileSize(file$)+" bytes)"
Else
Debug "imageSave failed ... "
EndIf
FreeImage(buffer)
MessageRequester("Image:", "Saved as:" + #CR$ + file$)
EndIf
EndProcedure
;
; main bit
;
UsePNGImageDecoder()
OpenWindow(#WINDOW_MAIN, 0, 0, 410, 410, "PNGTesting",#PB_Window_ScreenCentered)
CanvasGadget(#IMAGE_VIEW, 5, 5, 400, 400)
CatchImage(#IMAGE_BUFFER, ?PNGImage)
If StartDrawing(CanvasOutput(#IMAGE_VIEW))
Box(0, 0, 500, 500, #White)
DrawAlphaImage(ImageID(#IMAGE_BUFFER), 0, 0)
DrawingMode(#PB_2DDrawing_Outlined)
Box(0, 0, 400, 400, #Black)
StopDrawing()
EndIf
GadgetToolTip(#IMAGE_VIEW, "Right click to save, Escape to Quit")
AddKeyboardShortcut(#WINDOW_MAIN, #PB_Shortcut_Escape,2)
Repeat
Event = WaitWindowEvent(1)
If Event = #PB_Event_CloseWindow Or (Event = #PB_Event_Menu And EventMenu() = 2)
Quit = #True
EndIf
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #IMAGE_VIEW
Select EventType()
Case #PB_EventType_RightClick
ImageSave(#IMAGE_VIEW)
EndSelect
EndSelect
EndSelect
Until Quit = #True
End
DataSection
PNGImage:
IncludeBinary "HALFMD.png"
EndDataSection
Dave