* * *    
Главная » Статьи » Код PB

Просмотров: 1388 | Дата: 29.03.2024 | Коментарии (0)

Конвертор изоброжения в html



Code
; maak van plaatje een website..  
; test

#title = "HTML TEST: Picture to Html color code, P.v.C. 2009"
#width = 640
#height = 180
UseJPEGImageDecoder()
UsePNGImageDecoder()
Global zoom.b=1

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)+"1"+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)+"#000000"+Chr(34)+"><tr><td>"
  htm.s + "<table width="+Chr(34)+Str(wi*zoom)+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)+">"
  GetObject_(ImageID(0), SizeOf(BITMAP), bmp1.BITMAP)
  *px.long
  For y1=0 To bmp1\bmHeight-1
  y = bmp1\bmHeight-y1-1
  htm.s + "<tr height="+Chr(34)+Str(zoom)+Chr(34)+">"
  *px = bmp1\bmBits + y * bmp1\bmWidthBytes  
  For x=0 To bmp1\bmWidth-1
  pin1.l = *px\l
  If *px\l&$ff>-1
  If pin1<>pon.l  
  b.l = *px\l&$ff  
  g.l = *px\l>>8&$ff  
  r.l = *px\l>>16&$ff  
  red.s = "0"+Hex(r)
  green.s = "0"+Hex(g)
  blue.s = "0"+Hex(b)  
  ht.s = "<td bgColor="+Chr(34)+"#"+Right(red,2)+Right(green,2)+Right(blue,2)+Chr(34)+"></td>"
  pon.l = pin1.l  
  EndIf  
  htm.s + ht.s  
  EndIf
  *px + SizeOf(LONG)-1  
  wevent = WindowEvent()  
  If wevent = #PB_Event_CloseWindow : y1=he: x=wi: EndIf
  Next
  htm.s + "</tr>"
  SetGadgetState(7, y1*bmp1\bmWidth)
  Next
  DeleteObject_(bmp1)  
  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-80, 20, 0, 400)
  TextGadget( 3, #width-80, 42, 80, 20, "Width 0")  
  TrackBarGadget( 4, 0, 80, #width-80, 20, 0, 400)
  TextGadget( 5, #width-80, 82, 80, 20, "Height 0")  
  TrackBarGadget( 9, 60, 120, #width-60, 20, 1, 10)  
  TextGadget( 10, 4, 122, 56, 20, "Zoom 1x")
  ButtonGadget( 6, 0, 160, 40, 20, "Start")
  ProgressBarGadget(7, 40, 160, #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)
  If ImageWidth(0)>400
  wi.l = 400
  Else
  wi.l = ImageWidth(0)
  EndIf
  If ImageHeight(0)>400
  he.l = 400
  Else
  he.l = ImageHeight(0)
  EndIf
  SetGadgetState(2, wi)
  SetGadgetState(4, he)
  SetGadgetText(3, "Width "+Str(wi))
  SetGadgetText(5, "Height "+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, "Width "+Str(wi))
  SetGadgetText(5, "Height "+Str(he))
  SetGadgetAttribute(7, #PB_ProgressBar_Maximum, wi*he.l)  
  Case 4; height
  he.l = GetGadgetState(4)
  SetGadgetText(3, "Width "+Str(wi))
  SetGadgetText(5, "Height "+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, pic.s+".html")
  WriteStringN(0, htm.s)
  CloseFile(0)
  RunProgram("explorer.exe", pic.s+".html", "")
  EndIf  
  EndIf
  DisableGadget(6, 0)
  Case 9
  zoom = GetGadgetState(9)
  SetGadgetText(10, "Zoom "+Str(zoom)+"x")
  EndSelect
  EndIf
  Until wevent = #PB_Event_CloseWindow  
  CloseWindow(0)
EndIf
End










Сайт посвящён языку программирования PureBasic — коммерческий компилятор языка программирования, использующего синтаксис BASIC. Предназначен для создания кроссплатформенных приложений для AmigaOS, Linux, Microsoft Windows, Windows NT и Mac OS X. Разработан компанией Fantaisie Software.