[Résolu Par Denis] Problem avec mon code et gdiplus :(

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: Problem avec mon code et gdiplus :(

Message par celtic88 »

@Denis, au final le code c'est ça?

Code : Tout sélectionner

EnableExplicit

Prototype GdiplusStartup(*a,b,c)
Prototype GdipDisposeImage(*a)
Prototype GdiplusShutdown(*a)
Prototype GdipCreateBitmapFromHBITMAP(*a, b, *c)
Prototype GdipSaveImageToFile(*a,b.s,*d,*e)
Prototype GdipGetImageWidth(a,*b)
Prototype GdipGetImageHeight(a,*b)
Prototype GdipCreateBitmapFromScan0(a,b,c,d,*e,*f)
Prototype GdipGetImageEncodersSize(a,b)
Prototype GdipGetImageEncoders(a, b, *c)
Prototype GdipCloneBitmapArea(a.f,b.f,c.f,d.f,e,*g,*h)
Prototype GdipGetImageGraphicsContext(*a, *b)
Prototype GdipDrawImageRectI(*a, *b,c,d,e,f)
Prototype GdipDeleteGraphics(*a)
Global  *lib_gdiplus = OpenLibrary(#PB_Any, "GDIPlus.dll") 
Global  GdiplusStartup_.GdiplusStartup=GetFunction(*lib_gdiplus,"GdiplusStartup")
Global  GdipDisposeImage_.GdipDisposeImage=GetFunction(*lib_gdiplus,"GdipDisposeImage")
Global  GdiplusShutdown_.GdiplusShutdown=GetFunction(*lib_gdiplus,"GdiplusShutdown")
Global  GdipCreateBitmapFromHBITMAP_.GdipCreateBitmapFromHBITMAP=GetFunction(*lib_gdiplus,"GdipCreateBitmapFromHBITMAP")
Global  GdipSaveImageToFile_.GdipSaveImageToFile=GetFunction(*lib_gdiplus,"GdipSaveImageToFile")
Global  GdipGetImageWidth_.GdipGetImageWidth=GetFunction(*lib_gdiplus,"GdipGetImageWidth")
Global  GdipGetImageHeight_.GdipGetImageHeight=GetFunction(*lib_gdiplus,"GdipGetImageHeight")
Global  GdipGetImageEncodersSize_.GdipGetImageEncodersSize=GetFunction(*lib_gdiplus,"GdipGetImageEncodersSize")
Global  GdipGetImageEncoders_.GdipGetImageEncoders=GetFunction(*lib_gdiplus,"GdipGetImageEncoders")
Global  GdipCloneBitmapArea_.GdipCloneBitmapArea=GetFunction(*lib_gdiplus,"GdipCloneBitmapArea")
Global  GdipCreateBitmapFromScan0_.GdipCreateBitmapFromScan0=GetFunction(*lib_gdiplus,"GdipCreateBitmapFromScan0")
Global  GdipGetImageGraphicsContext_.GdipGetImageGraphicsContext=GetFunction(*lib_gdiplus,"GdipGetImageGraphicsContext")
Global  GdipDrawImageRectI_.GdipDrawImageRectI=GetFunction(*lib_gdiplus,"GdipDrawImageRectI")
Global  GdipDeleteGraphics_.GdipDeleteGraphics=GetFunction(*lib_gdiplus,"GdipDeleteGraphics")

Structure GdiplusStartupInput 
  GdiPlusVersion.l 
  *DebugEventCallback.DEBUG_EVENT
  SuppressBackgroundThread.l 
  SuppressExternalCodecs.l 
EndStructure 
Structure EncoderParameter
  Guid.GUID
  NumberOfValues.l
  Type.l
  *Value
EndStructure
Structure EncoderParameters
  Count.l
  Parameter.EncoderParameter[1]
EndStructure
Structure ImageCodecInfo
  clsid.CLSID
  formatID.GUID
  *codecName
  *dllName
  *formatDescription
  *filenameExtension
  *mimeType
  flags.l
  version.l
  sigCount.l
  sigSize.l
  *sigPattern
  *sigMask
EndStructure

Declare _Multiple_Monitor_GetSize(*ByrefXw,*ByrefXy)
Declare __ScreenCapture_andSave(Image_Save_Pathe.s,ResizeWidth = #NUL,ResizeHeight=#NUL,imageQuality=100)

Define DESKTOP_dir.s=Space(#MAX_PATH)
SHGetSpecialFolderPath_(#Null,@DESKTOP_dir,#CSIDL_DESKTOP,#False)
Define Filename.s=DESKTOP_dir + "\Test.tif"

__ScreenCapture_andSave(Filename)

CloseLibrary(*lib_gdiplus)

Procedure __ScreenCapture_andSave(Image_Save_Pathe.s,ResizeWidth = #NUL,ResizeHeight=#NUL,imageQuality=100)
  ;Create Screen Capture
  Protected DesktopWidth =GetSystemMetrics_(#SM_CXSCREEN)
  Protected DesktopHeight=GetSystemMetrics_(#SM_CYSCREEN)
  _Multiple_Monitor_GetSize(@DesktopWidth,@DesktopHeight)
  Protected hwndwin=GetDesktopWindow_()
  Protected DChwndwin=GetDC_(hwndwin)
  Protected CDChwndwin=CreateCompatibleDC_(DChwndwin)
  Protected  *iBitmap=CreateCompatibleBitmap_(DChwndwin,DesktopWidth,DesktopHeight)
  SelectObject_(CDChwndwin,*iBitmap)
  BitBlt_(CDChwndwin,0,0,DesktopWidth,DesktopHeight,DChwndwin, 0, 0, #SRCCOPY)
  
  ;Draw cUrsor
  Protected tCursor.CURSORINFO
  tCursor\cbSize=SizeOf(CURSORINFO)
  GetCursorInfo_(@tCursor)
  Protected hIcon=CopyIcon_(tCursor\hCursor)
  Protected tInfo.ICONINFO
  GetIconInfo_(hIcon,@tInfo)
  DeleteObject_(tInfo\hbmMask)
  If  tInfo\hbmColor <> #NUL : DeleteObject_( tInfo\hbmColor): EndIf
  DrawIcon_(CDChwndwin,tCursor\ptScreenPos\x-tInfo\xHotspot,tCursor\ptScreenPos\y-tInfo\yHotspot,hIcon)
  DestroyIcon_(hIcon)
  
  ;clean
  ReleaseDC_(hwndwin,DChwndwin)
  DeleteDC_(CDChwndwin)
  
  ;Start Gdiplus
  Protected GdiplusStartupInput.GdiplusStartupInput\GdiPlusVersion=1
  Protected *token
  Debug GdiplusStartup_(@*token, @GdiplusStartupInput,#NUL)
  
  ;Convert Image to gdip image
  Protected *GdipBitmap
  GdipCreateBitmapFromHBITMAP_( *iBitmap,0,@*GdipBitmap)
  
  DeleteObject_(*iBitmap)
  
  ;Get all encoders for images and save it in a array
  Protected Encount,Encsize
  GdipGetImageEncodersSize_(@Encount,@Encsize)
  Protected CodecCount = Encsize / SizeOf(ImageCodecInfo)
  Protected Dim tinfo.ImageCodecInfo(CodecCount-1 )
  GdipGetImageEncoders_(Encount,Encsize,@tinfo())
  
  ;Get encoder types by Extension File
  Protected ic
  Protected.s Extension = GetExtensionPart(Image_Save_Pathe),EncExtension
  For ic=0 To Encount-1  
    EncExtension = PeekS(tinfo(ic)\filenameExtension, -1, #PB_Unicode)  
    If FindString( EncExtension,Extension,1,#PB_String_NoCase)  > 0 :Break:EndIf
  Next
  
  ;   Protected imageQuality=50 ;Set the quality of image only jpg and jpeg
  
  ; Encoder settings for "tiff" image
  #GDIP_EPTLONG = 4  ; 32 bit unsigned integer
  Protected *pParams
  Protected encoderparams.EncoderParameters
  #GDIP_PXF24RGB = $00021808 ; 24 bpp; 8 bits for each RGB
  
  If FindString("JPG;JPEG",Extension,1,#PB_String_NoCase)  > 0
    With encoderparams.EncoderParameters
      \Count = 1
      \Parameter[0]\Type = #GDIP_EPTLONG
      \Parameter[0]\NumberOfValues = 1
      \parameter[0]\Value = @imageQuality
    EndWith
    ;copy clsid to guid
    CopyMemory(?clsid_EncoderQuality, encoderparams\parameter[0]\Guid, SizeOf(GUID))
    *pParams = @encoderparams
  ElseIf FindString( "TIF;TIFF",Extension,1,#PB_String_NoCase)  > 0
    #GDIP_EVTCOMPRESSIONLZW = 2 ;TIFF: LZW compression
    Protected ColorDepth = 24
    Protected Compression = #GDIP_EVTCOMPRESSIONLZW
    
    Protected Nb_EncoderParameter = 2
    
    Protected *memory = AllocateMemory(Nb_EncoderParameter * SizeOf(EncoderParameter))
    
    Protected *Params.EncoderParameters  = *memory
    
    *Params\Count = Nb_EncoderParameter
    
    Protected *AdresseBase = *memory + OffsetOf(EncoderParameters\Parameter)  
    
    Protected *Parameter.EncoderParameter = *AdresseBase 
    With *Parameter
      CopyMemory(?clsid_EPGCOLORDEPTH, \guid, SizeOf(guid))
      \NumberOfValues = 1
      \Type = 4   ; valeur à personnaliser
      \Value = @ColorDepth
    EndWith
    
    *Parameter.EncoderParameter = *AdresseBase +  SizeOf(EncoderParameter)
    
    With *Parameter
      CopyMemory(?clsid_EPGCOMPRESSION, \guid, SizeOf(guid))
      \NumberOfValues = 1
      \Type = 4   ; valeur à personnaliser
      \Value = @Compression
    EndWith
    
    *pParams = *Params
  ElseIf FindString( "BMP",Extension,1,#PB_String_NoCase)  > 0
    Protected xw,xy
    GdipGetImageWidth_(*GdipBitmap,@xw)
    GdipGetImageHeight_(*GdipBitmap,@xy)
    Protected *NewGdipBitmap
    GdipCloneBitmapArea_(0,0,xw,xy,#GDIP_PXF24RGB,*GdipBitmap,@*NewGdipBitmap)
    GdipDisposeImage_(*GdipBitmap)
    *GdipBitmap = *NewGdipBitmap
    *pParams =0
  EndIf
  
  If ResizeWidth <> #NUL Or ResizeHeight <> #NUL
    ;Resize image
    Protected *NewResGdipBitmap,*ImageGraphicsContext
    Protected ResiW=ResizeWidth, ResiH=ResizeHeight
    GdipCreateBitmapFromScan0_(ResiW,ResiH,#NUL,#GDIP_PXF24RGB,0,@*NewResGdipBitmap)
    GdipGetImageGraphicsContext_(*NewResGdipBitmap,@*ImageGraphicsContext)
    GdipDrawImageRectI_(*ImageGraphicsContext,*GdipBitmap,0,0,ResiW,ResiH)
    GdipDisposeImage_(*GdipBitmap)
    GdipDeleteGraphics_(*ImageGraphicsContext)
    *GdipBitmap = *NewResGdipBitmap
  EndIf
  
  ;Save Image
  GdipSaveImageToFile_(*GdipBitmap,Image_Save_Pathe,tinfo(ic)\clsid,*pParams)
  
  ;clean
  GdipDisposeImage_(*GdipBitmap)
  GdiplusShutdown_(*token)
  
  ProcedureReturn #True
EndProcedure

Procedure _Multiple_Monitor_GetSize(*ByrefXw,*ByrefXy)
  Protected iI= 0,m_StateFlags,Tw,Ty
  Protected StDISPLAY.DISPLAY_DEVICE
  StDISPLAY\cb= SizeOf(DISPLAY_DEVICE)
  Protected dev.DEVMODE
  dev\dmSize = SizeOf(DEVMODE)
  While EnumDisplayDevices_(#NUL,iI,@StDISPLAY,#NUL)
    iI + 1
    m_StateFlags = StDISPLAY\StateFlags
    If (m_StateFlags & #DISPLAY_DEVICE_ACTIVE) And Not (m_StateFlags & #DISPLAY_DEVICE_MIRRORING_DRIVER)
      If Not EnumDisplaySettings_(PeekS(@StDISPLAY\DeviceName), #ENUM_CURRENT_SETTINGS,@dev):Continue:EndIf
      Debug PeekS(@StDISPLAY\DeviceString)
      Tw +dev\dmPelsWidth
      Ty + dev\dmPelsHeight
    EndIf
  Wend
  If Tw > 0 And Ty > 0
    PokeL(*ByrefXw, Tw)
    PokeL(*ByrefXy, Ty)
  EndIf
EndProcedure

DataSection
  clsid_EncoderQuality:
  Data.l $1D5BE4B5
  Data.w $FA4A
  Data.w $452D
  Data.b $9C,$DD,$5D,$B3,$51,$05,$E7,$EB
  
  clsid_EPGCOLORDEPTH:
  Data.l $66087055
  Data.w $AD66
  Data.w $4C7C
  Data.b $9A,$18,$38,$A2,$31,$0B,$83,$37
  
  clsid_EPGCOMPRESSION:
  Data.l $E09D739D
  Data.w $CCD4
  Data.w $44EE
  Data.b $8E,$BA,$3F,$BF,$8B,$E4,$FC,$58
EndDataSection
.....i Love Pb :)
Anonyme2
Messages : 3518
Inscription : jeu. 22/janv./2004 14:31
Localisation : Sourans

Re: Problem avec mon code et gdiplus :(

Message par Anonyme2 »

Voilà ton code que j'ai corrigé et qui fonctionne en PB 5.40 b7 en 32 et 64 bit en mode Ascii et en mode UNICODE.

J'ai ajouté quelques tests sur les fonction GDI+ pour m'y retrouver un peu dans ton code.
J'ai ajouté la constante #Ok = 0 pour les tests

Les modis importantes sont mises entre
;// ******************* Modifié Modifié Modifié *******************

;// ******************* Fin Modifié Fin Modifié Fin Modifié *******************
1ère modif, je t'en ai parlé hier mais pas de modif.
Tu dois tester que tu récupère bien une valeur dans ta boucle, j'ai ajouté la variable indice_tableau = -1

Code : Tout sélectionner

      ;// *******************  Modifié  Modifié  Modifié   *******************
      Protected indice_tableau = -1
      For ic=0 To Encount-1
            EncExtension = PeekS(tinfo(ic)\filenameExtension, -1, #PB_Unicode)
            If FindString( EncExtension,Extension,1,#PB_String_NoCase)  > 0
                  indice_tableau = ic
                  Break
            EndIf
      Next
      
      If indice_tableau = - 1
            MessageRequester("Erreur","GdipCreateBitmapFromHBITMAP_() a échouée",16)
            GdipDisposeImage_(*GdipBitmap)
            GdiplusShutdown_(*token)
      Else
            Debug "ic = " + Str(ic)
      EndIf
      ;// *******************  Fin Modifié  Fin Modifié   Fin Modifié *******************
2ème modif:
tu dois allouer de la mémoire pour la structure EncoderParameters, regardes comme j'ai modifié.
J'ai compris tout de suite, en compilant, on a une erreur mémoire, tu dois te poser la question sur la taille de allocatememory et comme tu alloues sur des tailles de structures, c'est presque sur que l'erreur vient de là.

Essaye de modifier en utilisant un tableau comme le conseille Nico.

Code : Tout sélectionner

            ;// *******************  Modifié  Modifié  Modifié   *******************
            ; Protected *memory = AllocateMemory(Nb_EncoderParameter * SizeOf(EncoderParameter))
            Protected *memory = AllocateMemory(SizeOf(EncoderParameters) + ((Nb_EncoderParameter-1) * SizeOf(EncoderParameter)))
            ;// *******************  Fin Modifié  Fin Modifié   Fin Modifié *******************
3ème modif, ça ne marchait que si on compile en Unicode, j'ai modifié comme ceci pour GdipSaveImageToFile_():

Code : Tout sélectionner

      ;// *******************  Modifié  Modifié  Modifié   *******************
      ;Save Image
      Macro STRINGTOUNICODE(DestString, StringtoConvert)
            CompilerIf #PB_Compiler_Unicode
                  DestString = StringtoConvert
            CompilerElse
                  DestString = Space(StringByteLength(StringtoConvert, #PB_Unicode) + 1)
                  PokeS(@DestString, StringtoConvert, -1, #PB_Unicode)
            CompilerEndIf
      EndMacro
      Protected name$ = ""
      STRINGTOUNICODE(name$, Image_Save_Pathe)
      ; GdipSaveImageToFile_(*GdipBitmap, @Image_Save_Pathe,tinfo(ic)\clsid,*pParams)
      If GdipSaveImageToFile_(*GdipBitmap, name$, tinfo(ic)\clsid,*pParams) <> #Ok
            MessageRequester("Erreur","GdipSaveImageToFile_() a échouée",16)
            GdipDisposeImage_(*GdipBitmap)
            GdiplusShutdown_(*token)
            End
      EndIf
      ;// *******************  Fin Modifié  Fin Modifié   Fin Modifié *******************

Voilà le code complet, je n'ai pas testé pour les autres formats.

Code : Tout sélectionner

EnableExplicit
Define .i

Prototype GdiplusStartup(*a,b,c)
Prototype GdipDisposeImage(*a)
Prototype GdiplusShutdown(*a)
Prototype GdipCreateBitmapFromHBITMAP(*a, b, *c)
Prototype GdipSaveImageToFile(*a,b.s,*d,*e)
Prototype GdipGetImageWidth(a,*b)
Prototype GdipGetImageHeight(a,*b)
Prototype GdipCreateBitmapFromScan0(a,b,c,d,*e,*f)
Prototype GdipGetImageEncodersSize(a,b)
Prototype GdipGetImageEncoders(a, b, *c)
Prototype GdipCloneBitmapArea(a.f,b.f,c.f,d.f,e,*g,*h)
Prototype GdipGetImageGraphicsContext(*a, *b)
Prototype GdipDrawImageRectI(*a, *b,c,d,e,f)
Prototype GdipDeleteGraphics(*a)
Global  *lib_gdiplus = OpenLibrary(#PB_Any, "GDIPlus.dll")
Global  GdiplusStartup_.GdiplusStartup=GetFunction(*lib_gdiplus,"GdiplusStartup")
Global  GdipDisposeImage_.GdipDisposeImage=GetFunction(*lib_gdiplus,"GdipDisposeImage")
Global  GdiplusShutdown_.GdiplusShutdown=GetFunction(*lib_gdiplus,"GdiplusShutdown")
Global  GdipCreateBitmapFromHBITMAP_.GdipCreateBitmapFromHBITMAP=GetFunction(*lib_gdiplus,"GdipCreateBitmapFromHBITMAP")
Global  GdipSaveImageToFile_.GdipSaveImageToFile=GetFunction(*lib_gdiplus,"GdipSaveImageToFile")
Global  GdipGetImageWidth_.GdipGetImageWidth=GetFunction(*lib_gdiplus,"GdipGetImageWidth")
Global  GdipGetImageHeight_.GdipGetImageHeight=GetFunction(*lib_gdiplus,"GdipGetImageHeight")
Global  GdipGetImageEncodersSize_.GdipGetImageEncodersSize=GetFunction(*lib_gdiplus,"GdipGetImageEncodersSize")
Global  GdipGetImageEncoders_.GdipGetImageEncoders=GetFunction(*lib_gdiplus,"GdipGetImageEncoders")
Global  GdipCloneBitmapArea_.GdipCloneBitmapArea=GetFunction(*lib_gdiplus,"GdipCloneBitmapArea")
Global  GdipCreateBitmapFromScan0_.GdipCreateBitmapFromScan0=GetFunction(*lib_gdiplus,"GdipCreateBitmapFromScan0")
Global  GdipGetImageGraphicsContext_.GdipGetImageGraphicsContext=GetFunction(*lib_gdiplus,"GdipGetImageGraphicsContext")
Global  GdipDrawImageRectI_.GdipDrawImageRectI=GetFunction(*lib_gdiplus,"GdipDrawImageRectI")
Global  GdipDeleteGraphics_.GdipDeleteGraphics=GetFunction(*lib_gdiplus,"GdipDeleteGraphics")

Structure GdiplusStartupInput
      GdiPlusVersion.l
      *DebugEventCallback.DEBUG_EVENT
      SuppressBackgroundThread.l
      SuppressExternalCodecs.l
EndStructure
;- EncoderParameter
Structure EncoderParameter
      Guid.GUID
      NumberOfValues.l
      Type.l
      *Value
EndStructure
;- EncoderParameters
Structure EncoderParameters
      Count.l
      Parameter.EncoderParameter[1]
EndStructure
Structure ImageCodecInfo
      clsid.CLSID
      formatID.GUID
      *codecName
      *dllName
      *formatDescription
      *filenameExtension
      *mimeType
      flags.l
      version.l
      sigCount.l
      sigSize.l
      *sigPattern
      *sigMask
EndStructure

Declare _Multiple_Monitor_GetSize(*ByrefXw,*ByrefXy)
Declare __ScreenCapture_andSave(Image_Save_Pathe.s,ResizeWidth = #NUL,ResizeHeight=#NUL,imageQuality=100)

Define DESKTOP_dir.s=Space(#MAX_PATH)
SHGetSpecialFolderPath_(#Null,@DESKTOP_dir,#CSIDL_DESKTOP,#False)
Define Filename.s=DESKTOP_dir + "\Test.tif"

__ScreenCapture_andSave(Filename)

CloseLibrary(*lib_gdiplus)

Procedure __ScreenCapture_andSave(Image_Save_Pathe.s,ResizeWidth = #NUL,ResizeHeight=#NUL,imageQuality=100)
      ;Create Screen Capture
      Protected DesktopWidth =GetSystemMetrics_(#SM_CXSCREEN)
      Protected DesktopHeight=GetSystemMetrics_(#SM_CYSCREEN)
      _Multiple_Monitor_GetSize(@DesktopWidth,@DesktopHeight)
      Protected hwndwin=GetDesktopWindow_()
      Protected DChwndwin=GetDC_(hwndwin)
      Protected CDChwndwin=CreateCompatibleDC_(DChwndwin)
      Protected  *iBitmap=CreateCompatibleBitmap_(DChwndwin,DesktopWidth,DesktopHeight)
      SelectObject_(CDChwndwin,*iBitmap)
      BitBlt_(CDChwndwin,0,0,DesktopWidth,DesktopHeight,DChwndwin, 0, 0, #SRCCOPY)
      
      ;Draw cUrsor
      Protected tCursor.CURSORINFO
      tCursor\cbSize=SizeOf(CURSORINFO)
      GetCursorInfo_(@tCursor)
      Protected hIcon=CopyIcon_(tCursor\hCursor)
      Protected tInfo.ICONINFO
      GetIconInfo_(hIcon,@tInfo)
      DeleteObject_(tInfo\hbmMask)
      If  tInfo\hbmColor <> #NUL : DeleteObject_( tInfo\hbmColor): EndIf
      DrawIcon_(CDChwndwin,tCursor\ptScreenPos\x-tInfo\xHotspot,tCursor\ptScreenPos\y-tInfo\yHotspot,hIcon)
      DestroyIcon_(hIcon)
      
      ;clean
      ReleaseDC_(hwndwin,DChwndwin)
      DeleteDC_(CDChwndwin)
      
      ;Start Gdiplus
      Protected GdiplusStartupInput.GdiplusStartupInput\GdiPlusVersion=1
      Protected *token
      
      ;// *******************  Modifié  Modifié  Modifié   *******************
      #Ok = 0
      ;// *******************  Fin Modifié  Fin Modifié   Fin Modifié *******************
      If GdiplusStartup_(@*token, @GdiplusStartupInput,#NUL) <> #Ok
            MessageRequester("Erreur","GdiplusStartup_() a échouée",16)
            End
      EndIf
      
      ;Convert Image to gdip image
      Protected *GdipBitmap
      If GdipCreateBitmapFromHBITMAP_(*iBitmap,0,@*GdipBitmap) <> #Ok
            MessageRequester("Erreur","GdipCreateBitmapFromHBITMAP_() a échouée",16)
            GdiplusShutdown_(*token)
            End
      EndIf
      
      DeleteObject_(*iBitmap)
      
      ;Get all encoders for images and save it in a array
      Protected Encount,Encsize
      If GdipGetImageEncodersSize_(@Encount,@Encsize) <> #Ok
            MessageRequester("Erreur","GdipGetImageEncodersSize_() a échouée",16)
            GdipDisposeImage_(*GdipBitmap)
            GdiplusShutdown_(*token)
            End
      EndIf
      
      Protected CodecCount = Encsize / SizeOf(ImageCodecInfo)
      Protected Dim tinfo.ImageCodecInfo(CodecCount-1 )
      If GdipGetImageEncoders_(Encount,Encsize,@tinfo()) <> #Ok
            MessageRequester("Erreur","GdipGetImageEncoders_() a échouée",16)
            GdipDisposeImage_(*GdipBitmap)
            GdiplusShutdown_(*token)
            End
      EndIf
      
      ;Get encoder types by Extension File
      Protected ic
      Protected.s Extension = GetExtensionPart(Image_Save_Pathe),EncExtension
      
      
      
      ;// *******************  Modifié  Modifié  Modifié   *******************
      Protected indice_tableau = -1
      For ic=0 To Encount-1
            EncExtension = PeekS(tinfo(ic)\filenameExtension, -1, #PB_Unicode)
            If FindString( EncExtension,Extension,1,#PB_String_NoCase)  > 0
                  indice_tableau = ic
                  Break
            EndIf
      Next
      
      If indice_tableau = - 1
            MessageRequester("Erreur","GdipCreateBitmapFromHBITMAP_() a échouée",16)
            GdipDisposeImage_(*GdipBitmap)
            GdiplusShutdown_(*token)
      Else
            Debug "ic = " + Str(ic)
      EndIf
      ;// *******************  Fin Modifié  Fin Modifié   Fin Modifié *******************
      
      
      
      ;   Protected imageQuality=50 ;Set the quality of image only jpg and jpeg
      
      ; Encoder settings for "tiff" image
      #GDIP_EPTLONG = 4  ; 32 bit unsigned integer
      Protected *pParams
      Protected encoderparams.EncoderParameters
      #GDIP_PXF24RGB = $00021808 ; 24 bpp; 8 bits for each RGB
      
      If FindString("JPG;JPEG",Extension,1,#PB_String_NoCase)  > 0
            With encoderparams.EncoderParameters
                  \Count = 1
                  \Parameter[0]\Type = #GDIP_EPTLONG
                  \Parameter[0]\NumberOfValues = 1
                  \parameter[0]\Value = @imageQuality
            EndWith
            ;copy clsid to guid
            CopyMemory(?clsid_EncoderQuality, encoderparams\parameter[0]\Guid, SizeOf(GUID))
            *pParams = @encoderparams
            
      ElseIf FindString( "TIF;TIFF",Extension, 1,#PB_String_NoCase)  > 0
            #GDIP_EVTCOMPRESSIONLZW = 2 ;TIFF: LZW compression
            Protected ColorDepth = 24
            Protected Compression = #GDIP_EVTCOMPRESSIONLZW
            
            Protected Nb_EncoderParameter = 2
            
            
            ;// *******************  Modifié  Modifié  Modifié   *******************
            ; Protected *memory = AllocateMemory(Nb_EncoderParameter * SizeOf(EncoderParameter))
            Protected *memory = AllocateMemory(SizeOf(EncoderParameters) + ((Nb_EncoderParameter-1) * SizeOf(EncoderParameter)))
            ;// *******************  Fin Modifié  Fin Modifié   Fin Modifié *******************
            
            
            
            Protected *Params.EncoderParameters  = *memory
            
            *Params\Count = Nb_EncoderParameter
            
            Protected *AdresseBase = *memory + OffsetOf(EncoderParameters\Parameter)
            
            Protected *Parameter.EncoderParameter = *AdresseBase
            With *Parameter
                  CopyMemory(?clsid_EPGCOLORDEPTH, \guid, SizeOf(guid))
                  \NumberOfValues = 1
                  \Type = 4   ; valeur à personnaliser
                  \Value = @ColorDepth
            EndWith
            
            *Parameter.EncoderParameter = *AdresseBase +  SizeOf(EncoderParameter)
            
            With *Parameter
                  CopyMemory(?clsid_EPGCOMPRESSION, \guid, SizeOf(guid))
                  \NumberOfValues = 1
                  \Type = 4   ; valeur à personnaliser
                  \Value = @Compression
            EndWith
            
            *pParams = *Params
            
      ElseIf FindString( "BMP",Extension,1,#PB_String_NoCase)  > 0
            Protected xw,xy
            GdipGetImageWidth_(*GdipBitmap,@xw)
            GdipGetImageHeight_(*GdipBitmap,@xy)
            Protected *NewGdipBitmap
            GdipCloneBitmapArea_(0,0,xw,xy,#GDIP_PXF24RGB,*GdipBitmap,@*NewGdipBitmap)
            GdipDisposeImage_(*GdipBitmap)
            *GdipBitmap = *NewGdipBitmap
            *pParams =0
      EndIf
      
      If ResizeWidth <> #NUL Or ResizeHeight <> #NUL
            ;Resize image
            Protected *NewResGdipBitmap,*ImageGraphicsContext
            Protected ResiW=ResizeWidth, ResiH=ResizeHeight
            GdipCreateBitmapFromScan0_(ResiW,ResiH,#NUL,#GDIP_PXF24RGB,0,@*NewResGdipBitmap)
            GdipGetImageGraphicsContext_(*NewResGdipBitmap,@*ImageGraphicsContext)
            GdipDrawImageRectI_(*ImageGraphicsContext,*GdipBitmap,0,0,ResiW,ResiH)
            GdipDisposeImage_(*GdipBitmap)
            GdipDeleteGraphics_(*ImageGraphicsContext)
            *GdipBitmap = *NewResGdipBitmap
      EndIf
      
      
      
      ;// *******************  Modifié  Modifié  Modifié   *******************
      ;Save Image
      Macro STRINGTOUNICODE(DestString, StringtoConvert)
            CompilerIf #PB_Compiler_Unicode
                  DestString = StringtoConvert
            CompilerElse
                  DestString = Space(StringByteLength(StringtoConvert, #PB_Unicode) + 1)
                  PokeS(@DestString, StringtoConvert, -1, #PB_Unicode)
            CompilerEndIf
      EndMacro
      Protected name$ = ""
      STRINGTOUNICODE(name$, Image_Save_Pathe)
      ; GdipSaveImageToFile_(*GdipBitmap, @Image_Save_Pathe,tinfo(ic)\clsid,*pParams)
      If GdipSaveImageToFile_(*GdipBitmap, name$, tinfo(ic)\clsid,*pParams) <> #Ok
            MessageRequester("Erreur","GdipSaveImageToFile_() a échouée",16)
            GdipDisposeImage_(*GdipBitmap)
            GdiplusShutdown_(*token)
            End
      EndIf
      ;// *******************  Fin Modifié  Fin Modifié   Fin Modifié *******************
      
      ;clean
      GdipDisposeImage_(*GdipBitmap)
      GdiplusShutdown_(*token)
      
      ProcedureReturn #True
EndProcedure

Procedure _Multiple_Monitor_GetSize(*ByrefXw,*ByrefXy)
      Protected iI= 0,m_StateFlags,Tw,Ty
      Protected StDISPLAY.DISPLAY_DEVICE
      StDISPLAY\cb= SizeOf(DISPLAY_DEVICE)
      Protected dev.DEVMODE
      dev\dmSize = SizeOf(DEVMODE)
      While EnumDisplayDevices_(#NUL,iI,@StDISPLAY,#NUL)
            iI + 1
            m_StateFlags = StDISPLAY\StateFlags
            If (m_StateFlags & #DISPLAY_DEVICE_ACTIVE) And Not (m_StateFlags & #DISPLAY_DEVICE_MIRRORING_DRIVER)
                  If Not EnumDisplaySettings_(PeekS(@StDISPLAY\DeviceName), #ENUM_CURRENT_SETTINGS,@dev):Continue:EndIf
                  Debug PeekS(@StDISPLAY\DeviceString)
                  Tw +dev\dmPelsWidth
                  Ty + dev\dmPelsHeight
            EndIf
      Wend
      If Tw > 0 And Ty > 0
            PokeL(*ByrefXw, Tw)
            PokeL(*ByrefXy, Ty)
      EndIf
EndProcedure

DataSection
      clsid_EncoderQuality:
      Data.l $1D5BE4B5
      Data.w $FA4A
      Data.w $452D
      Data.b $9C,$DD,$5D,$B3,$51,$05,$E7,$EB
      
      clsid_EPGCOLORDEPTH:
      Data.l $66087055
      Data.w $AD66
      Data.w $4C7C
      Data.b $9A,$18,$38,$A2,$31,$0B,$83,$37
      
      clsid_EPGCOMPRESSION:
      Data.l $E09D739D
      Data.w $CCD4
      Data.w $44EE
      Data.b $8E,$BA,$3F,$BF,$8B,$E4,$FC,$58
EndDataSection
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: Problem avec mon code et gdiplus :(

Message par celtic88 »

merci @denis pour ta correction :).

juste une question! tu est sur qu il ya une erreur de "AllocateMemory" ?

car moi je ne vois aucune différence entre:
Nb_EncoderParameter * SizeOf(EncoderParameter)
et
EncoderParameters) + ((Nb_EncoderParameter-1) * SizeOf(EncoderParameter))
.....i Love Pb :)
Anonyme2
Messages : 3518
Inscription : jeu. 22/janv./2004 14:31
Localisation : Sourans

Re: Problem avec mon code et gdiplus :(

Message par Anonyme2 »

celtic88 a écrit :merci @denis pour ta correction :).

juste une question! tu est sur qu il ya une erreur de "AllocateMemory" ?

car moi je ne vois aucune différence entre:
Nb_EncoderParameter * SizeOf(EncoderParameter)
et
EncoderParameters) + ((Nb_EncoderParameter-1) * SizeOf(EncoderParameter))
Regardes bien le code que j'ai corrigé : attention il y a une structure EncoderParameters et une structure EncoderParameter.

Il y a un s à la fin de la première.

voilà ton code

Code : Tout sélectionner

Protected *memory = AllocateMemory(Nb_EncoderParameter * SizeOf(EncoderParameter))
et le mien

Code : Tout sélectionner

Protected *memory = AllocateMemory(SizeOf(EncoderParameters) + ((Nb_EncoderParameter-1) * SizeOf(EncoderParameter)))
tapes le code suivant et exécutes :

Code : Tout sélectionner

Debug Nb_EncoderParameter * SizeOf(EncoderParameter)
            
Debug SizeOf(EncoderParameters) + ((Nb_EncoderParameter-1) * SizeOf(EncoderParameter))
et dis-moi si les valeurs sont les mêmes, tu verras que non.
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: Problem avec mon code et gdiplus :(

Message par celtic88 »

Denis a écrit :
celtic88 a écrit :merci @denis pour ta correction :).

juste une question! tu est sur qu il ya une erreur de "AllocateMemory" ?

car moi je ne vois aucune différence entre:
Nb_EncoderParameter * SizeOf(EncoderParameter)
et
EncoderParameters) + ((Nb_EncoderParameter-1) * SizeOf(EncoderParameter))
Regardes bien le code que j'ai corrigé : attention il y a une structure EncoderParameters et une structure EncoderParameter.

Il y a un s à la fin de la première.

voilà ton code

Code : Tout sélectionner

Protected *memory = AllocateMemory(Nb_EncoderParameter * SizeOf(EncoderParameter))
et le mien

Code : Tout sélectionner

Protected *memory = AllocateMemory(SizeOf(EncoderParameters) + ((Nb_EncoderParameter-1) * SizeOf(EncoderParameter)))
tapes le code suivant et exécutes :

Code : Tout sélectionner

Debug Nb_EncoderParameter * SizeOf(EncoderParameter)
            
Debug SizeOf(EncoderParameters) + ((Nb_EncoderParameter-1) * SizeOf(EncoderParameter))
et dis-moi si les valeurs sont les mêmes, tu verras que non.

loll je suis un peut ouuuuf!

j ai pas vus le "s", et j'ai croyer que c'etait la meme structure :(
.....i Love Pb :)
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: Problem avec mon code et gdiplus :(

Message par celtic88 »

aloore remerci , le code est bien corriger
.....i Love Pb :)
Anonyme2
Messages : 3518
Inscription : jeu. 22/janv./2004 14:31
Localisation : Sourans

Re: Problem avec mon code et gdiplus :(

Message par Anonyme2 »

celtic88 a écrit :aloore remerci , le code est bien corriger
La saisie d'écran est pas mal avec ce code :D
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: Problem avec mon code et gdiplus :(

Message par celtic88 »

Denis a écrit :
celtic88 a écrit :aloore remerci , le code est bien corriger
La saisie d'écran est pas mal avec ce code :D
Hhhhh oui un peu :D , et la programmation en générale demande bcp de concentration

merci @Denis
.....i Love Pb :)
Anonyme2
Messages : 3518
Inscription : jeu. 22/janv./2004 14:31
Localisation : Sourans

Re: Problem avec mon code et gdiplus :(

Message par Anonyme2 »

J'ai travaillé entre 8 et 10 heures par jour, 6 jours par semaines pendant un an pour faire la doc et les exemples et le plus important, essayer de comprendre. Il n'y a pas beaucoup de documentation microsoft sur GDI+.

Aujourd'hui, il y a 660 fonctions soit environ 50 de plus que celles que j'ai décrites.
Je ne sais pas si j'aurais le temps, mais j'espère faire des exemples avec les nouvelles commandes et corriger ma doc, le passage au 64 bits a entrainé pleins d'erreurs que je suis en train de corriger.

Je suis patient et opiniâtre :D
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: Problem avec mon code et gdiplus :(

Message par celtic88 »

Denis a écrit :J'ai travaillé entre 8 et 10 heures par jour, 6 jours par semaines pendant un an pour faire la doc et les exemples et le plus important, essayer de comprendre. Il n'y a pas beaucoup de documentation microsoft sur GDI+.

Aujourd'hui, il y a 660 fonctions soit environ 50 de plus que celles que j'ai décrites.
Je ne sais pas si j'aurais le temps, mais j'espère faire des exemples avec les nouvelles commandes et corriger ma doc, le passage au 64 bits a entrainé pleins d'erreurs que je suis en train de corriger.

Je suis patient et opiniâtre :D
le mot merci ni pas suffisant vert ton travail, tu est le grand plus dans ce langage
J ai beaucoup appris par t documentation sur Gdip mémé avant que je connais PB
Je vous souhaite bonne chance
Et si vous voulez tout aide, je suis à votre service :)
.....i Love Pb :)
Avatar de l’utilisateur
blendman
Messages : 2017
Inscription : sam. 19/févr./2011 12:46

Re: [Résolu Par Denis] Problem avec mon code et gdiplus :(

Message par blendman »

@Celtic88 : c'est quoi ce gros projet sur lequel tu bosses avec GDI+ ? Un logiciel pour faire des effets sur des images ou autre chose ?
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: [Résolu Par Denis] Problem avec mon code et gdiplus :(

Message par celtic88 »

blendman a écrit :@Celtic88 : c'est quoi ce gros projet sur lequel tu bosses avec GDI+ ? Un logiciel pour faire des effets sur des images ou autre chose ?
exactement @blendman :)
.....i Love Pb :)
Répondre