Page 1 of 1

internet image in ImageGadget?

Posted: Sat Mar 17, 2007 12:26 pm
by hss
hi, kids.
how can i show up an internet loaded image (jpg/png..) in a ImageGadget? -- i'm getting it with the InternetReadFile-api..
after this, the image is stored in a variable...now: how can i give that var a valid ImageID()?

hope you got it ;-)
thanks for help.

Posted: Sat Mar 17, 2007 1:21 pm
by netmaestro
How's this?

Code: Select all

UseJPEGImageDecoder()

ProcedureDLL Read_File(file.s)  
  #INTERNET_FLAG_RELOAD = $80000000 
  Bytes.l = 0 
  *html  = AllocateMemory(50000)
  hInet.l = InternetOpen_("networkmaestro.com", 1, #Null, #Null, 0) 
  If hInet 
    hURL.l  = InternetOpenUrl_(hInet, file, #Null, 0, #INTERNET_FLAG_RELOAD, 0) 
    If hURL 
      If InternetReadFile_(hURL, *html, 50000, @Bytes) 
        CatchImage(0,*html, bytes)
        InternetCloseHandle_(hURL) 
      Else 
        ProcedureReturn 0
      EndIf 
    Else 
      ProcedureReturn 0
    EndIf    
    InternetCloseHandle_(hInet) 
  Else 
    ProcedureReturn 0
  EndIf 
  ProcedureReturn bytes
EndProcedure

If Read_File("http://www.networkmaestro.com/dreamer2.jpg")
  If IsImage(0) 
    If OpenWindow(0,0,0,ImageWidth(0),ImageHeight(0),"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
      If CreateGadgetList(WindowID(0))
        ImageGadget(0,0,0,0,0,ImageID(0))
        Repeat:Until WaitWindowEvent()=#WM_CLOSE
      EndIf
    EndIf
  EndIf
endif

Re: internet image in ImageGadget?

Posted: Sat Mar 17, 2007 1:24 pm
by PB

Code: Select all

; Win 98 or above ONLY, due to needing DeleteUrlCacheEntry API.

Procedure Download(url$,file$)
  DeleteUrlCacheEntry_(url$) ; Remove from cache first (if there).
  URLDownloadToFile_(0,url$,file$,0,0) ; Now download remote file.
EndProcedure

UseJPEGImageDecoder()

jpg$="c:\kylie-minogue.jpg"
Download("http://www.kylie-minogue.sztunie.pl/kylie-minogue.jpg",jpg$)

OpenWindow(0,200,200,600,428,"test")
CreateGadgetList(WindowID(0))
LoadImage(0,jpg$)
ImageGadget(0,0,0,600,428,ImageID(0))
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
DeleteFile(jpg$)

Posted: Sat Mar 17, 2007 1:29 pm
by netmaestro
Well your picture's nicer than mine, I'll concede that!

Posted: Sun Mar 18, 2007 9:53 am
by hss
yes! super-b..