Page 1 sur 1

LoadImage et image GIF

Publié : dim. 08/mars/2009 14:48
par lepiaf31
Bonjour ,
est-il possible de charger une image au format gif (qui n'est pas animée) ?
J'ai essayé avec LoadImage() mais ca ne marche pas.
Merci

Publié : dim. 08/mars/2009 18:07
par Kwai chang caine
Bonjour Lepiaf

Le GIF est un format proprietaire, peut etre plus maintenant, car je ne sais pas ou ça en est, mais il l'a été.
C'est pour ça que FRED n'a pas pu l'incorporer dans PB.

Y'a pas mal de codes qui trainent sur les forums.

Autrement si tu veux faire simple, utilise le WEBGADGET de PB, car comme il travaille aves les modules internes de Internet Explorer ou Fire Fox, le WebGadget gere nativement les GIF :D

Publié : dim. 08/mars/2009 18:10
par Stefou
Salut,

Ce n'est pas de moi, je ne sais plus où je l'ai pris,

Code : Tout sélectionner

Procedure LoadPictureFile(image,szFile.s) 
  ; 
  ; Loads 
  ;        BMP, GIF, JPG, WMF, EMF, ICO 
  ; 
  ;CallDebugger
  hFile = CreateFile_(szFile, #GENERIC_READ, 0, #Null, #OPEN_EXISTING, 0, #Null) 
  If hFile 
    dwFileSize = GetFileSize_(hFile, #Null) 
    hGlobal    = GlobalAlloc_(#GMEM_MOVEABLE, dwFileSize) 
    If hGlobal 
      pvData = GlobalLock_(hGlobal) 
      
      bRead = ReadFile_(hFile, pvData, dwFileSize, @dwBytesRead, #Null) 
      GlobalUnlock_(hGlobal) 
      
      If bRead 
        If CreateStreamOnHGlobal_(hGlobal, #True, @pstm.IStream) = #S_OK 
          If OleLoadPicture_(pstm, dwFileSize, #False,?IID_IPicture, @Bild.IPicture) = #S_OK 
            
            ; Here we got the IPicture Object 
            
            Bild\get_Height(@Height) 
            Bild\get_Width(@width) 
            
            hdc = GetDC_(GetDesktopWindow_()) 
            ScreenPixels_X = GetDeviceCaps_(hdc,#LOGPIXELSX) 
            ScreenPixels_Y = GetDeviceCaps_(hdc,#LOGPIXELSY) 
            ReleaseDC_(GetDesktopWindow_(),hdc) 
            
            PicHeight = (Height * ScreenPixels_X) / 2540 
            PicWidth  = (width  * ScreenPixels_Y) / 2540 
            
            result = CreateImage(image,PicWidth,PicHeight,32) 
            
            If result 
              hdc = StartDrawing(ImageOutput(image)) 
                Bild\Render(hdc,0,PicHeight,PicWidth,-PicHeight,0,0,width,Height,0) 
              StopDrawing() 
            EndIf 
            
            Bild\Release() 
          EndIf 
          pstm\Release() 
        EndIf 
      EndIf 
    EndIf 
    CloseHandle_(hFile) 
  EndIf 
  ProcedureReturn image 
  
  DataSection 
    IID_IPicture: 
    Data.l $7BF80980 
    Data.w $BF32,$101A 
    Data.b $8B,$BB,$00,$AA,$00,$30,$0C,$AB 
  EndDataSection 
EndProcedure 

file$=OpenFileRequester("","","",0)

LoadPictureFile(0,file$) 
SaveImage(0,"c:\test_gif.bmp")

Publié : dim. 08/mars/2009 18:11
par Kwai chang caine
Y'a aussi ça de CNESM purearea

Code : Tout sélectionner

InitMovie() 

OpenWindow(1,0,0,500,500,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
LoadMovie(1, OpenFileRequester("Choose a .gif","*.gif","",0)) 
ResizeMovie(1,0,0,WindowWidth(1),WindowHeight(1)) 
PlayMovie(1, WindowID(1)) 

Repeat 
Until WaitWindowEvent()=#PB_Event_CloseWindow

Publié : dim. 08/mars/2009 18:15
par Kwai chang caine
Ou ça de Michael Holderried (mueckerich)

Code : Tout sélectionner

;- Window Constants 
; 
#Window_0 = 0 
#SizeWindowX = 400 
#SizeWindowY = 200 

#SS_CENTERIMAGE = $200 
#WS_EX_TRANSPARENT = $20 

sWin.s 

hwnd = OpenWindow(#Window_0, 400, 200, #SizeWindowX , #SizeWindowY, "Container-Window", #PB_Window_SystemMenu) 
ButtonGadget(0,250,80,80,40,"End") 

If OpenLibrary(0,"ATL.DLL") 
If CallFunction(0,"AtlAxWinInit") ; Init has to be done to register the ATL Class "AtlAxWin" 
sWin = #PB_Compiler_Home + "Examples\#Commun\gif.gif" ; Thats an Example how to dispaly a lokal stored GIF Animation 
; sWin = "http://www.Somwhere.de//MyGif.gif" ; This Example shows how you can get the GIF Animation from the WEB 
; now we create the Window for our GIF, it might be possible to create this Window as Topmost Parent? 
hAxW = CreateWindowEx_(#WS_EX_TRANSPARENT | #SS_CENTERIMAGE, "AtlAxWin", sWin, #WS_VISIBLE | #WS_POPUP , 0, 0, 200, 200, hwnd, 0, GetModuleHandle_(0), 0) 
If hAxW 
SetParent_(hAxW, hwnd) ; Set GIF-Window as Child Window from our Container. Otherwise 
EndIf ; it will be a Window which can also be outside of our Container 
EndIf ; Try it out! (comment out SetParent) 
EndIf 

QuitFrm = 0 
Repeat 
EventID = WaitWindowEvent() 
Select EventID 
Case #WM_LBUTTONDOWN 
ReleaseCapture_() 
;SendMessage_(hwnd, #WM_SYSCOMMAND, #SC_MOVE + #HTCAPTION, 0) ;To move (Drag) the Container Window 
SendMessage_(hAxW, #WM_SYSCOMMAND, #SC_MOVE + #HTCAPTION, 0) ;To move (Drag) the GIF within the Container Window 
Case #PB_Event_Gadget 
Select EventGadget() 
Case 0: QuitFrm = 1 
EndSelect 
Case #PB_Event_CloseWindow 
QuitFrm = 1 
EndSelect 
Until QuitFrm 

DestroyWindow_(hAxW) ; We have to desroy the Windows, otherwise you'll get a exeption 
End 

Publié : dim. 08/mars/2009 18:18
par Kwai chang caine
Ou celui la de PB

Code : Tout sélectionner

FileName$ = #PB_Compiler_Home + "Examples\#Commun\gif.gif" 
; with this routine we can get the needed full path For the WebGadget
Buffer$=Space(512) 
GetFullPathName_(FileName$,Len(Buffer$),@Buffer$,@FilePart) 
animgif$ = PeekS(@Buffer) 

If OpenWindow(0,200,200,450,200,"Test",#PB_Window_SystemMenu)
  CreateGadgetList(WindowID(0))
   animgif$=FileName$ ; You *must* specify the full path to the animgif for this to work!
  
  url$="about:<html><body scroll='no' leftmargin='0' topmargin='0'><img src='"+animgif$+"'></img></body></html>"
  WebGadget(0,50,20,100,150,url$)
  Repeat
    ev=WaitWindowEvent()
  Until ev=#PB_Event_CloseWindow
EndIf

Publié : dim. 08/mars/2009 18:23
par Kwai chang caine
Au fait STEFOU :roll:
Ton code y permet pas de visionner les GIF.....me trompe-je ??? :roll:
Je crois qu'il permet de les charger et de les sauvegarder en BMP.

Publié : dim. 08/mars/2009 18:37
par Anonyme
result = CreateImage(image,PicWidth,PicHeight,32)

If result
hdc = StartDrawing(ImageOutput(image))
Bild\Render(hdc,0,PicHeight,PicWidth,-PicHeight,0,0,width,Height,0)
StopDrawing()
EndIf

Donc un Drawimage devrais fonctionner :wink:

Publié : lun. 09/mars/2009 7:48
par Stefou
Au fait STEFOU
Ton code y permet pas de visionner les GIF.....me trompe-je ???
Je crois qu'il permet de les charger et de les sauvegarder en BMP.
Mon code...le code que j'ai posté permet un loadimage() avec des gif(et d'autre format), j'ai ajouter une sauvegarde en BMP pour vérifier si il marchait.


a+

Publié : sam. 14/mars/2009 12:09
par lepiaf31
Merci de vos reponses. Mais en fait je ne cherche pas à afficher l'image, c'est en fait une image que je télécharge sur le web (c'est pour cela que je n'ai pas le choix du format de l'image) et ensuite je manipule cette image pour détecter certaines formes et couleurs (avec StartDrawing() et compagnie).

@Stefou: ton code marche mais l'image n'est pas bien chargé :( :

par exemple, cette image gif :
Image

devient celle-ci après enregistrement (format png):
Image

Publié : sam. 14/mars/2009 12:45
par Anonyme
Ton stardrawing() doit certainement écrasé le canal alpha avec les autres couleurs , ou bien à l'enregistrement... pas vraiment de solution toute faite en purebasic.

Publié : sam. 14/mars/2009 12:49
par Jacobus
Oui je crois que la transparence n'est pas gérée automatiquement.

Juste pour le fun, la proc de Stefou fonctionne très bien et permet l'affichage des GIF. Voici un petit viewer qui peut tenir dans une procédure et dans un soft de visualisation...

Code : Tout sélectionner

Procedure LoadPictureFile(image,szFile.s) 
  ; 
  ; Loads 
  ;        BMP, GIF, JPG, WMF, EMF, ICO 
  ; 
  ;CallDebugger 
  hFile = CreateFile_(szFile, #GENERIC_READ, 0, #Null, #OPEN_EXISTING, 0, #Null) 
  If hFile 
    dwFileSize = GetFileSize_(hFile, #Null) 
    hGlobal    = GlobalAlloc_(#GMEM_MOVEABLE, dwFileSize) 
    If hGlobal 
      pvData = GlobalLock_(hGlobal) 
      
      bRead = ReadFile_(hFile, pvData, dwFileSize, @dwBytesRead, #Null) 
      GlobalUnlock_(hGlobal) 
      
      If bRead 
        If CreateStreamOnHGlobal_(hGlobal, #True, @pstm.IStream) = #S_OK 
          If OleLoadPicture_(pstm, dwFileSize, #False,?IID_IPicture, @Bild.IPicture) = #S_OK 
            
            ; Here we got the IPicture Object 
            
            Bild\get_Height(@Height) 
            Bild\get_Width(@width) 
            
            hdc = GetDC_(GetDesktopWindow_()) 
            ScreenPixels_X = GetDeviceCaps_(hdc,#LOGPIXELSX) 
            ScreenPixels_Y = GetDeviceCaps_(hdc,#LOGPIXELSY) 
            ReleaseDC_(GetDesktopWindow_(),hdc) 
            
            PicHeight = (Height * ScreenPixels_X) / 2540 
            PicWidth  = (width  * ScreenPixels_Y) / 2540 
            
            result = CreateImage(image,PicWidth,PicHeight,32) 
            
            If result 
              hdc = StartDrawing(ImageOutput(image)) 
                Bild\Render(hdc,0,PicHeight,PicWidth,-PicHeight,0,0,width,Height,0) 
              StopDrawing() 
            EndIf 
            
            Bild\Release() 
          EndIf 
          pstm\Release() 
        EndIf 
      EndIf 
    EndIf 
    CloseHandle_(hFile) 
  EndIf 
  ProcedureReturn image 
  
  DataSection 
    IID_IPicture: 
    Data.l $7BF80980 
    Data.w $BF32,$101A 
    Data.b $8B,$BB,$00,$AA,$00,$30,$0C,$AB 
  EndDataSection 
EndProcedure 

file$=OpenFileRequester("","","",0)
If file$
 LoadPictureFile(0,file$)
 imgx = ImageWidth(0) 
 imgy = ImageHeight(0)
 If OpenWindow(0,0,0,imgx+20,imgy+20,GetFilePart(file$),#PB_Window_SystemMenu | #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered)
  ImageGadget(0,10,10,imgx,imgy,ImageID(0))
 EndIf    
  Repeat 
   Event = WaitWindowEvent() 
   GadgetID = EventGadget()    
    Select Event          
     Case #PB_Event_Gadget                  
       Select GadgetID      
        Case 0 : MessageRequester("Image","Dimensions de "+GetFilePart(file$)+Chr(13)+Str(imgx)+" X "+Str(imgy)+" pixels")
         DisableGadget(0,1);évite le renouvellement du messagerequester        
       EndSelect
    EndSelect
  Until Event = #PB_Event_CloseWindow 
  End  
EndIf