<Picture To Html code> Colors seem wrong..
Posted: Sat Mar 14, 2009 12:16 pm
Hi there,
Just made a prog that tries to convert a picture to html page,
it works but very very slow and some colors are wrong with most
pictures i tried.
Code:
Idea's?
Just made a prog that tries to convert a picture to html page,
it works but very very slow and some colors are wrong with most
pictures i tried.
Code:
Code: Select all
#title = "HTML TEST: Picture to Html"
#width = 640
#height = 140
UseJPEGImageDecoder()
UsePNGImageDecoder()
Procedure say(in.s)
MessageRequester(#title, in.s)
EndProcedure
Procedure.s pic2htm(pic.s, wi.l, he.l)
If LoadImage(0, pic.s)
ResizeImage(0, wi, he, #PB_Image_Smooth)
htm.s = "<HTML><HEAD></HEAD><BODY>"
htm.s + "<table border="+Chr(34)+"0"+Chr(34)+" border="+Chr(34)+"0"+Chr(34)+" cellspacing="+Chr(34)+"0"+Chr(34)+" cellpadding="+Chr(34)+"0"+Chr(34)+" align="+Chr(34)+"center"+Chr(34)+" style="+Chr(34)+"border-collapse:collapse;"+Chr(34)+" bordercolor="+Chr(34)+"#CCCCCC"+Chr(34)+"><tr><td>"
htm.s + "<table width="+Chr(34)+Str(wi)+Chr(34)+" border="+Chr(34)+"0"+Chr(34)+" cellspacing="+Chr(34)+"0"+Chr(34)+" cellpadding="+Chr(34)+"0"+Chr(34)+" align="+Chr(34)+"center"+Chr(34)+">"
StartDrawing(ImageOutput(0))
For y = 0 To he
htm.s + "<tr height="+Chr(34)+"1"+Chr(34)+">"
For x = 0 To wi
pin.l = Point(x, y)
htm.s + "<td bgColor="+Chr(34)+"#"+LCase(Hex(Red(pin)))+LCase(Hex(Green(pin)))+LCase(Hex(Blue(pin)))+Chr(34)+"></td>"; </td>"
wevent = WindowEvent()
If wevent = #PB_Event_CloseWindow : y=he: x=wi: EndIf
Next
htm.s + "</tr>"
SetGadgetState(7, y*wi)
Next
StopDrawing()
htm.s + "</table></td></tr></table></BODY></HTML>"
FreeImage(0)
ProcedureReturn htm.s
Else
ProcedureReturn ""
EndIf
EndProcedure
If OpenWindow(0, 0, 0, #width, #height, #title, #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonGadget( 0, 0, 0, 40, 20, "File")
TextGadget( 1, 40, 2, #width-40, 20, "None")
TrackBarGadget( 2, 0, 40, #width-40, 20, 0, 1024)
TextGadget( 3, #width-40, 42, 40, 20, "0")
TrackBarGadget( 4, 0, 80, #width-40, 40, 0, 768)
TextGadget( 5, #width-40, 82, 40, 40, "0")
ButtonGadget( 6, 0, 120, 40, 20, "Start")
ProgressBarGadget(7, 40, 120, #width-40, 20, 0, 100)
Repeat
wevent=WaitWindowEvent()
If wevent=#PB_Event_Gadget
Select EventGadget()
Case 0; file
pic.s = OpenFileRequester("Select picture", "", "*.*", 0)
If LoadImage(0, pic.s)
SetGadgetText(1, pic.s)
wi.l = ImageWidth(0)
he.l = ImageHeight(0)
SetGadgetState(2, wi)
SetGadgetState(4, he)
SetGadgetText(3, Str(wi))
SetGadgetText(5, Str(he))
SetGadgetAttribute(7, #PB_ProgressBar_Maximum, wi*he.l)
SetGadgetState(7, 0)
FreeImage(0)
EndIf
Case 2; width
wi.l = GetGadgetState(2)
SetGadgetText(3, Str(wi))
SetGadgetAttribute(7, #PB_ProgressBar_Maximum, wi*he.l)
Case 4; height
he.l = GetGadgetState(4)
SetGadgetText(5, Str(he))
SetGadgetAttribute(7, #PB_ProgressBar_Maximum, wi*he.l)
Case 6; start/stop
DisableGadget(6, 1)
htm.s = pic2htm(pic.s, wi, he)
If htm.s=""
say("No valid picture file")
Else
If CreateFile(0, "C:\test.html")
WriteStringN(0, htm.s)
CloseFile(0)
RunProgram("explorer.exe", "C:\test.html", "")
EndIf
EndIf
DisableGadget(6, 0)
EndSelect
EndIf
Until wevent = #PB_Event_CloseWindow
CloseWindow(0)
EndIf
End