Its a quick hack but it works. Anyone can feel free to improve it. You can drag an image onto the executable to view it, or just launch the program. Press 'S' to save a tiled image.
Code: Select all
; TilePreview
; Copyright 2005 DracSoft
; This code is released under the GNU GPL.
; These comments must remain intact.
; (http://www.gnu.org/licenses/gpl.html)
UseJPEGImageDecoder()
UsePNGImageDecoder()
UseTGAImageDecoder()
UseTIFFImageDecoder()
tile.s = ProgramParameter()
OpenWindow(1,0,0,640,480,#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered|#PB_Window_TitleBar|#PB_Window_SystemMenu|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget,"DracSoft Tile Previewer")
HideWindow(1,1)
If tile<>""
LoadImage(1,tile)
Else
tile=OpenFileRequester("Choose a tile...","","All Files|*.*",1)
If tile<>""
LoadImage(1,tile)
Else
End
EndIf
EndIf
If IsImage(1)
SetWindowTitle(1,GetFilePart(tile)+" - "+GetWindowTitle(1))
HideWindow(1,0)
InitKeyboard()
Repeat
StartDrawing(WindowOutput())
For i=0 To (WindowWidth()/ImageWidth())+1
For j=0 To (WindowHeight()/ImageHeight())+1
DrawImage(UseImage(1),i*ImageWidth(),j*ImageHeight())
Next
Next
StopDrawing()
ExamineKeyboard()
If KeyboardReleased(#PB_Key_S)
xt=Val(InputRequester("Save Tiled Image","Enter the number of times to tile on x axis:",""))
If xt<=0
End
EndIf
yt=Val(InputRequester("Save Tiled Image","Enter the number of times to tile on y axis:",""))
If yt<=0
End
EndIf
outfile.s=SaveFileRequester("Choose the output file...","","BMP Files|*.bmp",0)
If outfile<>""
CreateImage(2,xt*ImageWidth(),yt*ImageHeight())
If IsImage(2)
UseImage(2)
StartDrawing(ImageOutput())
For i=0 To xt-1
For j=0 To yt-1
DrawImage(UseImage(1),i*ImageWidth(),j*ImageHeight())
Next
Next
If MessageRequester("Save Tiled Image","Draw pink gridlines at the right and bottom of every tile?",#PB_MessageRequester_YesNo)=6 ;yes
For i=1 To xt
Line(i*ImageWidth()-1,0,0,ImageHeight()*yt,RGB(255,0,255))
Next
For j=1 To yt
Line(0,j*ImageHeight()-1,ImageWidth()*xt,0,RGB(255,0,255))
Next
EndIf
StopDrawing()
If SaveImage(2,outfile,#PB_ImagePlugin_BMP)=0
MessageRequester("Error","Couldn't create the image file.")
EndIf
Else
MessageRequester("Error","Couldn't create in-memory image.")
EndIf
EndIf
EndIf
event=WaitWindowEvent()
Until event=#PB_Event_CloseWindow
End
Else
MessageRequester("Error","Couldn't load image.")
End
EndIf