[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

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

Message par celtic88 »

Slt tout les membres de ce forum FR :D
bonbon , dans mon simple code la ici présent j'essaie de prendre un capture d'écran et apres convertir et sauvegarder la capture au format désiré !. et opss :( !j'obtiens un erreur sur la line 116 "accès memoire invalide " ? , alors je suis Débutant dans ce langage est je sai pas ou est l erreur exacte .
merci a vous de me répondre :).

le code

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.l
EndStructure
Structure EncoderParameters
  Count.l
  Parameter.EncoderParameter[28]
EndStructure
Structure ImageCodecInfo
  clsid.CLSID
  formatID.GUID
  *codecName
  *dllName
  *formatDescription
  *filenameExtension
  *mimeType
  flags.i
  version.i
  sigCount.i
  sigSize.i
  *sigPattern
  *sigMask
EndStructure 

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

Declare __ScreenCapture_andSave(Image_Save_Pathe.s,ResizeWidth = #NUL,ResizeHeight=#NUL)
__ScreenCapture_andSave(Filename)

CloseLibrary(*lib_gdiplus)

Procedure __ScreenCapture_andSave(Image_Save_Pathe.s,ResizeWidth = #NUL,ResizeHeight=#NUL)
  ;Create Screen Capture
  Protected DesktopWidth =GetSystemMetrics_(#SM_CXSCREEN)
  Protected DesktopHeight=GetSystemMetrics_(#SM_CYSCREEN)
  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 Dim tinfo.ImageCodecInfo(Encount-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)  
    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
    With encoderparams.EncoderParameters
      \Count = 1
      \Parameter[0]\Type = #GDIP_EPTLONG
      \Parameter[0]\NumberOfValues = 1
      \parameter[0]\Value = @ColorDepth
    EndWith
    With encoderparams.EncoderParameters
      \Count = 2
      \Parameter[1]\Type = #GDIP_EPTLONG
      \Parameter[1]\NumberOfValues = 1
      \parameter[1]\Value = @Compression
    EndWith
    CopyMemory(?clsid_EPGCOLORDEPTH, encoderparams\parameter[0]\Guid, SizeOf(GUID))
    CopyMemory(?clsid_EPGCOMPRESSION, encoderparams\parameter[1]\Guid, SizeOf(GUID))
    *pParams = @encoderparams
  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

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
Dernière modification par celtic88 le dim. 27/sept./2015 21:03, modifié 1 fois.
.....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 »

Spock, merci pour ta réponse cher
mai je dois travailler avec 'Gdiplus' pour avoir plus de possibilité et des affects a appliquer sur les images dans mon groos projet!
.....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 »

l'exemple qui j'ai donné dans mon poste c est just un demo de mon code pour just decouvrir l erreur
.....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 »

spok ;
regarde la mon code son avoir modifier et englober tout les procédure en un seul le code marche tree bien bizzzar :roll:


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.l
EndStructure
Structure EncoderParameters
Count.l
Parameter.EncoderParameter[28]
EndStructure
Structure ImageCodecInfo
clsid.CLSID
formatID.GUID
*codecName
*dllName
*formatDescription
*filenameExtension
*mimeType
flags.i
version.i
sigCount.i
sigSize.i
*sigPattern
*sigMask
EndStructure

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

Define DesktopWidth =GetSystemMetrics_(#SM_CXSCREEN)
Define DesktopHeight=GetSystemMetrics_(#SM_CYSCREEN)
Define hwndwin=GetDesktopWindow_()
Define DChwndwin=GetDC_(hwndwin)
Define CDChwndwin=CreateCompatibleDC_(DChwndwin)
Global *iBitmap=CreateCompatibleBitmap_(DChwndwin,DesktopWidth,DesktopHeight)
SelectObject_(CDChwndwin,*iBitmap)
BitBlt_(CDChwndwin,0,0,DesktopWidth,DesktopHeight,DChwndwin, 0, 0, #SRCCOPY)

;Get cUrsor
Define tCursor.CURSORINFO
tCursor\cbSize=SizeOf(CURSORINFO)
GetCursorInfo_(@tCursor)
Define hIcon=CopyIcon_(tCursor\hCursor)
Define 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)

ReleaseDC_(hwndwin,DChwndwin)
DeleteDC_(CDChwndwin)

Define GdiplusStartupInput.GdiplusStartupInput\GdiPlusVersion=1

Define *token
Debug GdiplusStartup_(@*token, @GdiplusStartupInput,#NUL)
Define *GdipBitmap
Debug GdipCreateBitmapFromHBITMAP_( *iBitmap,0,@*GdipBitmap)
DeleteObject_(*iBitmap)

Define Encount,Encsize
GdipGetImageEncodersSize_(@Encount,@Encsize)
Dim tinfo.ImageCodecInfo(Encount-1)
GdipGetImageEncoders_(Encount,Encsize,@tinfo())

Define ic
Define.s Extension = GetExtensionPart(Filename),EncExtension

For ic=0 To Encount-1
EncExtension = PeekS(tinfo(ic)\filenameExtension)
If FindString( EncExtension,Extension,-1,#PB_String_NoCase) > 0 :Break:EndIf
Next

Define imageQuality=50
#GDIP_EPTLONG = 4 ; 32 bit unsigned integer
Define *pParams
Define 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
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
Define ColorDepth = 24
Define Compression = #GDIP_EVTCOMPRESSIONLZW
With encoderparams.EncoderParameters
\Count = 1
\Parameter[0]\Type = #GDIP_EPTLONG
\Parameter[0]\NumberOfValues = 1
\parameter[0]\Value = @ColorDepth
EndWith
With encoderparams.EncoderParameters
\Count = 2
\Parameter[1]\Type = #GDIP_EPTLONG
\Parameter[1]\NumberOfValues = 1
\parameter[1]\Value = @Compression
EndWith
CopyMemory(?clsid_EPGCOLORDEPTH, encoderparams\parameter[0]\Guid, SizeOf(GUID))
CopyMemory(?clsid_EPGCOMPRESSION, encoderparams\parameter[1]\Guid, SizeOf(GUID))
*pParams = @encoderparams
ElseIf FindString( "BMP",Extension,-1,#PB_String_NoCase) > 0
Define xw,xy
GdipGetImageWidth_(*GdipBitmap,@xw)
GdipGetImageHeight_(*GdipBitmap,@xy)
Define *NewGdipBitmap
GdipCloneBitmapArea_(0,0,xw,xy,#GDIP_PXF24RGB,*GdipBitmap,@*NewGdipBitmap)
GdipDisposeImage_(*GdipBitmap)
*GdipBitmap = *NewGdipBitmap
*pParams =0
EndIf

;Resize image
Define *NewResGdipBitmap,*ImageGraphicsContext
Define ResiW=500, ResiH=500
GdipCreateBitmapFromScan0_(ResiW,ResiH,#NUL,#GDIP_PXF24RGB,0,@*NewResGdipBitmap)
GdipGetImageGraphicsContext_(*NewResGdipBitmap,@*ImageGraphicsContext)
GdipDrawImageRectI_(*ImageGraphicsContext,*GdipBitmap,0,0,ResiW,ResiH)
GdipDisposeImage_(*GdipBitmap)
GdipDeleteGraphics_(*ImageGraphicsContext)
*GdipBitmap = *NewResGdipBitmap

GdipSaveImageToFile_(*GdipBitmap,Filename,tinfo(ic)\clsid,*pParams)
GdipDisposeImage_(*GdipBitmap)

GdiplusShutdown_(*token)

CloseLibrary(*lib_gdiplus)

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
:(

Image
.....i Love Pb :)
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Re: Problem avec mon code et gdiplus :(

Message par nico »

Remplace:

Code : Tout sélectionner

Structure ImageCodecInfo
  clsid.CLSID
  formatID.GUID
  *codecName
  *dllName
  *formatDescription
  *filenameExtension
  *mimeType
  flags.i
  version.i
  sigCount.i
  sigSize.i
  *sigPattern
  *sigMask
EndStructure 
par

Code : Tout sélectionner

Structure ImageCodecInfo
  clsid.CLSID
  formatID.GUID
  *codecName
  *dllName
  *formatDescription
  *filenameExtension
  *mimeType
  flags.l
  version.l
  sigCount.l
  sigSize.l
  *sigPattern
  *sigMask
EndStructure 
Ensuite, il y a toujours un problème, le nombre de codecs ne semble pas être bon; on va le déterminer en divisant encsize par la taille de la structure ImageCodecInfo

Ce qui donne:

Code : Tout sélectionner

  ;Get all encoders for images and save it in a array
  Protected.l Encount,Encsize,CodecCount
  GdipGetImageEncodersSize_(@Encount,@Encsize)
  Debug "---+++---"
  Debug Encount ; = 5 chez moi
  Debug Encsize
  Debug Encsize / SizeOf(ImageCodecInfo) ; = 13 au lieu de 5 ??
  CodecCount = Encsize / SizeOf(ImageCodecInfo)
  Protected Dim tinfo.ImageCodecInfo(CodecCount - 1)
  GdipGetImageEncoders_(Encount,Encsize,@tinfo(0))
Anonyme2
Messages : 3518
Inscription : jeu. 22/janv./2004 14:31
Localisation : Sourans

Re: Problem avec mon code et gdiplus :(

Message par Anonyme2 »

Comme l'a dit Nico,

il y a un problème avec la structure ImageCodecInfo, c'est une erreur de ma part dans la doc GDI+ (je suis en train de reprendre la doc et tous les exemples).
Une autre structure fausse, au moins en 64 bit : EncoderParameter

voici les structures justes je pense.

Code : Tout sélectionner

Structure EncoderParameter ;{
      ; http://msdn.microsoft.com/library/Default.asp?url=/library/en-us/gdicpp/GDIPlus/GDIPlusReference/Classes/EncoderParameter.asp
      guid.GUID
      numberOfValues.l
      type.l
      *value
EndStructure ;}


 	Structure ImageCodecInfo
      clsid.CLSID
      formatID.GUID
      *codecName  
      *dllName
      *formatDescription
      *filenameExtension
      *mimeType
      flags.l
      version.l
      sigCount.l
      sigSize.l
      *sigPattern
      *sigMask
EndStructure
Ensuite, les membres *codecName , *dllName, *formatDescription, *filenameExtension et *mimeType sont des chaines unicode et pas autre chose !!!!!!!
// ImageCodecInfo structure
//--------------------------------------------------------------------------

class ImageCodecInfo
{
public:
CLSID Clsid;
GUID FormatID;
const WCHAR* CodecName;
const WCHAR* DllName;
const WCHAR* FormatDescription;
const WCHAR* FilenameExtension;
const WCHAR* MimeType;
DWORD Flags;
DWORD Version;
DWORD SigCount;
DWORD SigSize;
const BYTE* SigPattern;
const BYTE* SigMask;
};
il faut modifier les structures ci-dessus dans ton code et la ligne suivante dans ton code (boucle For ic = 0 To Encount-1):

Code : Tout sélectionner

EncExtension = PeekS(tinfo(ic)\filenameExtension, -1, #PB_Unicode)
puis la ligne qui suit est fausse, le test n'est jamais vrai

Code : Tout sélectionner

If FindString(EncExtension, Extension, -1,#PB_String_NoCase)  > 0 : :Break EndIf
pourquoi le -1, c'est 1 normalement je pense

Code : Tout sélectionner

If FindString(EncExtension, Extension, 1,#PB_String_NoCase)  > 0 : :Break EndIf
on obtient une erreur sur la taille du tableau, normal ic a une valeur supérieur de 1 que celle de la boucle puisque l'on passe toutes les occurences de la boucle.

ensuite on n'arrive bien dans la zone des fichiers tiff mais ça plante encore.

Expliques-moi pourquoi la structures EncoderParameters est déclarée comme ceci :

Code : Tout sélectionner

Structure EncoderParameters
      Count.l
      Parameter.EncoderParameter[28]
EndStructure
alors que c'est

Code : Tout sélectionner

Structure EncoderParameters ;{
  Count.l                        ; nombre d'élément du tableau Parameter.EncoderParameter
  Parameter.EncoderParameter[1]  ; tableau de type EncoderParameter
EndStructure ;}
Microsoft
class EncoderParameters
{
public:
UINT Count; // Number of parameters in this structure
EncoderParameter Parameter[1]; // Parameter values
};

A partir de là changes la structure ou expliques-moi ce 28 pour Parameter.EncoderParameter[28]

Parameter.EncoderParameter est un pointeur sur un tableau dont normalement on ne connait pas la taille à l'avance, il faut faire évoluer le pointeur pour obtenir les bonnes données.

D'ailleurs je pense que la valeur 0 devrait aller pour déclarer la structure, je ferais des essais.
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 »

Collll ça marche :D ,nico et Denis merci pour votre réponse ,
.....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 »

Expliques-moi pourquoi la structures EncoderParameters est déclarée comme ceci :

Code : Tout sélectionner

Structure EncoderParameters
      Count.l
      Parameter.EncoderParameter[28]
EndStructure
alors que c'est

Code : Tout sélectionner

Structure EncoderParameters ;{
  Count.l                        ; nombre d'élément du tableau Parameter.EncoderParameter
  Parameter.EncoderParameter[1]  ; tableau de type EncoderParameter
EndStructure ;}
Microsoft
class EncoderParameters
{
public:
UINT Count; // Number of parameters in this structure
EncoderParameter Parameter[1]; // Parameter values
};

A partir de là changes la structure ou expliques-moi ce 28 pour Parameter.EncoderParameter[28]

Parameter.EncoderParameter est un pointeur sur un tableau dont normalement on ne connait pas la taille à l'avance, il faut faire évoluer le pointeur pour obtenir les bonnes données.

D'ailleurs je pense que la valeur 0 devrait aller pour déclarer la structure, je ferais des essais.

lol pardonnez moi je suis entrain de bakli les chose :p,, j ai pensé que Parameter[1] sert a déterminer le nombre des codecs a apporter a l'image :(
.....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 »

.....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 »

c'est de moi je crois :D
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Re: Problem avec mon code et gdiplus :(

Message par nico »

Bien vu Denis, comme j'avais une image générée, j'ai pas cherché plus loin.

Du coup le code complet corrigé, ça donne quoi?
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 :c'est de moi je crois :D
abon c'est toi l'auteur de ce super tutoriel sur gpi+ :o aloor monsieur laisse moi t dire un grand respect a toi vraiment t trop fort et merci encore pour le superbe travaille que tu fais pour donner de l'aide a des débutant comme moi :(

et a propos de mon code ci je trompe pas mon code doit ressembler a ça :(

Code : Tout sélectionner

Structure EncoderParameter
  Guid.GUID
  NumberOfValues.l
  Type.l
  *Value
EndStructure
Structure EncoderParameters
  Count.l
  Parameter.EncoderParameter[1]
EndStructure

Nb_EncoderParameter = 2

*memory = AllocateMemory(SizeOf(Nb_EncoderParameter * SizeOf(EncoderParameter)))

*Params.EncoderParameters  = *memory

*Params\Count = Nb_EncoderParameter

*AdresseBase = *memory + OffsetOf(EncoderParameters\Parameter)  

*Parameter.EncoderParameter = *AdresseBase 
With *Parameter
  CopyMemory(?clsid_EPGCOLORDEPTH, \guid, SizeOf(guid))
  \NumberOfValues = 1
  \Type = 4   ; valeur à personnaliser
  \Value = @ColorDepth
EndWith

*Parameter.EncoderParameter = *AdresseBase + (1 * SizeOf(EncoderParameter))

With *Parameter
  CopyMemory(?clsid_EPGCOMPRESSION, \guid, SizeOf(guid))
  \NumberOfValues = 1
  \Type = 4   ; valeur à personnaliser
  \Value = @Compression
EndWith

DataSection  
  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 :)
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Re: Problem avec mon code et gdiplus :(

Message par nico »

Merci mais il ne fait rien ce code alors que le premier me générait une image. :roll:
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Re: Problem avec mon code et gdiplus :(

Message par nico »

@Denis,

Pour certaines structures, il serait plus intéressant d'utiliser les array, ainsi on peut les redimensionner sans passer par des pointeurs.
Structure EncoderParameters ;{
Count.l ; nombre d'élément du tableau Parameter.EncoderParameter
Array Parameter.EncoderParameter(1) ; tableau de type EncoderParameter
EndStructure ;}
Anonyme2
Messages : 3518
Inscription : jeu. 22/janv./2004 14:31
Localisation : Sourans

Re: Problem avec mon code et gdiplus :(

Message par Anonyme2 »

nico a écrit :@Denis,

Pour certaines structures, il serait plus intéressant d'utiliser les array, ainsi on peut les redimensionner sans passer par des pointeurs.
Structure EncoderParameters ;{
Count.l ; nombre d'élément du tableau Parameter.EncoderParameter
Array Parameter.EncoderParameter(1) ; tableau de type EncoderParameter
EndStructure ;}
Tu as raison Nico.

Dans mes codes, je n'utilise pratiquement jamais de tableaux, c'est juste ma façon de faire (j'aime pas les tableaux) :( .

Je vais regarder de plus près...
Répondre