[Résolu Par Denis] Problem avec mon code et gdiplus :(
Publié : sam. 26/sept./2015 14:52
Slt tout les membres de ce forum FR 
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

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

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