Most dragged and dropped images do obey that line but some don't and I don't know why.
Can anyone see the flaw in my code?
Code: Select all
; // ------------------------------------------
; // Beginning of visual designer created code //
; // ------------------------------------------
; // Load the various needed plugins for this program //
UsePNGImageDecoder()
UsePNGImageEncoder()
UseJPEGImageDecoder()
; // Visual designer created constants code and windows //
Define EventID, MenuID, GadgetID, WindowID
Enumeration 1
#Window_iDrag
EndEnumeration
#WindowIndex = #PB_Compiler_EnumerationValue
Enumeration 1
; Window_iDrag
#Gadget_iDrag_Myimage
#Gadget_iDrag_Saveimage
#Gadget_iDrag_Exitprogram
#Gadget_iDrag_Messages
EndEnumeration
#GadgetIndex = #PB_Compiler_EnumerationValue
Enumeration 1
#Image_iDrag_Myimage
EndEnumeration
#ImageIndex = #PB_Compiler_EnumerationValue
CatchImage(#Image_iDrag_Myimage,?_OPT_iDrag_Myimage)
;- Custom Resize Images
ResizeImage(#Image_iDrag_Myimage, 640, 480)
DataSection
_OPT_iDrag_Myimage:
IncludeBinary "Images\antelopes.jpg"
EndDataSection
Procedure.i Window_iDrag()
If OpenWindow(#Window_iDrag,0,0,650,545,"Drag and drop an image on target from anywhere, then save to storage",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
ImageGadget(#Gadget_iDrag_Myimage,5,5,640,480,ImageID(#Image_iDrag_Myimage),#PB_Image_Border|#PB_Image_Raised)
ButtonGadget(#Gadget_iDrag_Saveimage,5,490,200,25,"Save image to storage")
SetGadgetFont(#Gadget_iDrag_Saveimage,LoadFont(#Gadget_iDrag_Saveimage,"Comic Sans MS",10))
ButtonGadget(#Gadget_iDrag_Exitprogram,445,490,200,25,"Exit program immediately")
SetGadgetFont(#Gadget_iDrag_Exitprogram,LoadFont(#Gadget_iDrag_Exitprogram,"Comic Sans MS",10))
TextGadget(#Gadget_iDrag_Messages,5,520,640,20,"Messages")
SetGadgetColor(#Gadget_iDrag_Messages,#PB_Gadget_FrontColor,$800000)
SetGadgetFont(#Gadget_iDrag_Messages,LoadFont(#Gadget_iDrag_Messages,"Comic Sans MS",9,#PB_Font_Bold))
HideWindow(#Window_iDrag,#False)
ProcedureReturn WindowID(#Window_iDrag)
EndIf
EndProcedure
; // ------------------------------------------
; // End of visual designer created code //
; // ------------------------------------------
; // All program specific variables, structures etc //
Global CurrentDirectory.s = GetCurrentDirectory()
Global ImageDirectory.s = CurrentDirectory.s + "Storage\Images\"
Global DroppedImageId.i
Declare SaveDroppedImage()
; // Save the image that was dropped on the imagegadget //
Procedure SaveDroppedImage()
If IsImage(DroppedImageId.i)
ImageToSave.i = CreateImage(#PB_Any, GadgetWidth(#Gadget_iDrag_Myimage), GadgetHeight(#Gadget_iDrag_Myimage))
If IsImage(ImageToSave.i)
If StartDrawing(ImageOutput(ImageToSave.i))
DrawImage(ImageID(DroppedImageId.i), 0, 0)
StopDrawing()
EndIf
RandomFileName.s = Str(Random(2000, 1))
SaveImage(ImageToSave.i, ImageDirectory.s + RandomFileName.s + ".png", #PB_ImagePlugin_PNG)
SetGadgetText(#Gadget_iDrag_Messages, "Saved new image: " + ImageDirectory.s + RandomFileName.s + ".png")
EndIf
DroppedImageId.i = #False
If IsImage(DroppedImageId.i)
FreeImage(DroppedImageId.i)
EndIf
If IsImage(ImageToSave.i)
FreeImage(ImageToSave.i)
EndIf
Else
SetGadgetText(#Gadget_iDrag_Messages, "No image has been dropped as yet, default is still in the frame")
EndIf
EndProcedure
; // //
If Window_iDrag()
Define quitiDrag = #False
ResizeGadget(#Gadget_iDrag_Myimage, #PB_Ignore, #PB_Ignore, DesktopScaledX(640), DesktopScaledY(480))
ResizeImage(#Image_iDrag_Myimage, DesktopScaledX(640), DesktopScaledY(480))
SetGadgetState(#Gadget_iDrag_Myimage, ImageID(#Image_iDrag_Myimage))
EnableGadgetDrop(#Gadget_iDrag_Myimage, #PB_Drop_Image, #PB_Drag_Copy)
Repeat
EventID = WaitWindowEvent()
MenuID = EventMenu()
GadgetID = EventGadget()
WindowID = EventWindow()
Select EventID
Case #PB_Event_CloseWindow
Select WindowID
Case #Window_iDrag
quitiDrag = #True
EndSelect
Case #PB_Event_GadgetDrop
Select GadgetID
Case #Gadget_iDrag_Myimage
; Get the image id of the image that was dropped from anywhere
DroppedImageId.i = EventDropImage(#PB_Any)
ResizeGadget(#Gadget_iDrag_Myimage, #PB_Ignore, #PB_Ignore, DesktopScaledX(640), DesktopScaledY(480))
ResizeImage(DroppedImageId.i, DesktopScaledX(640), DesktopScaledY(480), #PB_Image_Smooth)
SetGadgetState(#Gadget_iDrag_Myimage, ImageID(DroppedImageId.i))
SetGadgetText(#Gadget_iDrag_Messages, "Image was dropped from somewhere with an ID of: " + Str(DroppedImageId.i))
EndSelect
Case #PB_Event_Gadget
Select GadgetID
Case #Gadget_iDrag_Saveimage
SaveDroppedImage()
Case #Gadget_iDrag_Exitprogram
quitiDrag = #True
EndSelect
EndSelect
Until quitiDrag
CloseWindow(#Window_iDrag)
EndIf
End