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