Приветствую
Имеется код сохранения активного окна в файл в формате png, пропуская его через фильтр grayscale. Как мне уменьшить битность изображения? Гугл подсказывает, что нужно использовать функцию _GDIPlus_BitmapLockBits.
Ниже приведу используемый код, однако пока _GDIPlus_BitmapLockBits не оказывает эффект:

Ниже приведу используемый код, однако пока _GDIPlus_BitmapLockBits не оказывает эффект:
Код:
#include <ScreenCapture.au3>
MakeScreenShot()
Exit
Func MakeScreenShot()
$ActiveWindow = WinGetHandle("[active]")
if $ActiveWindow=="" Then Return 0
$Pos = WinGetClientSize("[active]")
if $Pos==0 Then Return 0
$proc = WinGetProcess("[active]")
$filename = @YEAR & @MON & @MDAY & "-" & @HOUR & @MIN & @SEC
_GDIPlus_Startup()
$HBITMAP = _ScreenCapture_CaptureWnd ("", $ActiveWindow, 0, 0, $Pos[0], $Pos[1], False)
$fFreeBmp = True
$hBmp = _GDIPlus_BitmapCreateFromHBITMAP($HBITMAP)
$hContext = _GDIPlus_ImageGetGraphicsContext($hBmp)
_GDIPlus_BitmapLockBits($hBmp, 0, 0, $Pos[0], $Pos[1], $GDIP_ILMWRITE, $GDIP_PXF16GRAYSCALE)
_Greyscale($hBmp, $hContext)
_GDIPlus_ImageSaveToFile($hBmp, @ScriptDir & "\" & $filename & ".png")
_GDIPlus_GraphicsDispose($hContext)
_WinAPI_DeleteObject($HBITMAP)
_GDIPlus_BitmapDispose ($hBmp)
_GDIPlus_Shutdown()
EndFunc
Func _Greyscale($hImage, $hImageContext)
Local $tNegMatrix, $pNegMatrix, $hIA
$hIA = _GDIPlus_ImageAttributesCreate()
$aImageSize = _GDIPlus_ImageGetDimension($hImage)
If $hImage Then
$tNegMatrix = _GDIPlus_ColorMatrixCreateGrayScale()
$pNegMatrix = DllStructGetPtr($tNegMatrix)
_GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $pNegMatrix)
_GDIPlus_GraphicsDrawImageRectRectIA($hImageContext, $hImage, 0, 0, $aImageSize[0], $aImageSize[1], 0, 0, $aImageSize[0], $aImageSize[1], $hIA)
_GDIPlus_ImageAttributesDispose($hIA)
EndIf
EndFunc
Func _GDIPlus_ImageGetDimension($hImage)
Local $aSize[2], $aResult
$aResult = DllCall($ghGDIPDll, "uint", "GdipGetImageDimension", "hwnd", $hImage, "float*", 0, "float*", 0)
If @error Then Return SetError(@error, @extended, -1)
$GDIP_STATUS = $aResult[0]
If $GDIP_STATUS Then Return -1
$aSize[0] = $aResult[2]
$aSize[1] = $aResult[3]
Return $aSize
EndFunc ;==>_GDIPlus_ImageGetDimension
Func _GDIPlus_ImageAttributesCreate()
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateImageAttributes", "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
Return $aResult[1]
EndFunc ;==>_GDIPlus_ImageAttributesCreate
Func _GDIPlus_ColorMatrixCreateGrayScale()
Local Const $GDIP_RLUM = 0.3086
Local Const $GDIP_GLUM = 0.6094
Local Const $GDIP_BLUM = 0.0820
Local Const $tagGDIPCOLORMATRIX = "float m[25];"
Local $iI, $iJ, $tCM, $aLums[4] = [$GDIP_RLUM, $GDIP_GLUM, $GDIP_BLUM, 0]
$tCM = DllStructCreate($tagGDIPCOLORMATRIX)
For $iI = 0 To 3
For $iJ = 1 To 3
DllStructSetData($tCM, "m", $aLums[$iI], $iI * 5 + $iJ)
Next
Next
DllStructSetData($tCM, "m", 1, 19)
DllStructSetData($tCM, "m", 1, 25)
Return $tCM
EndFunc ;==>_GDIPlus_ColorMatrixCreateGrayScale
Func _GDIPlus_ImageAttributesSetColorMatrix($hImageAttributes, $iColorAdjustType = 0, $fEnable = False, $pClrMatrix = 0, $pGrayMatrix = 0, $iColorMatrixFlags = 0)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetImageAttributesColorMatrix", "hwnd", $hImageAttributes, "int", $iColorAdjustType, "int", $fEnable, "ptr", $pClrMatrix, "ptr", $pGrayMatrix, "int", $iColorMatrixFlags)
If @error Then Return SetError(@error, @extended, False)
Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_ImageAttributesSetColorMatrix
Func _GDIPlus_GraphicsDrawImageRectRectIA($hGraphics, $hImage, $nSrcX, $nSrcY, $nSrcWidth, $nSrcHeight, $nDstX, $nDstY, $nDstWidth, $nDstHeight, $hImageAttributes = 0, $iUnit = 2)
Local $aResult = DllCall($ghGDIPDll, "int", "GdipDrawImageRectRect", "hwnd", $hGraphics, "hwnd", $hImage, "float", $nDstX, "float", _
$nDstY, "float", $nDstWidth, "float", $nDstHeight, "float", $nSrcX, "float", $nSrcY, "float", $nSrcWidth, "float", _
$nSrcHeight, "int", $iUnit, "hwnd", $hImageAttributes, "int", 0, "int", 0)
If @error Then Return SetError(@error, @extended, False)
Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_GraphicsDrawImageRectRectIA
Func _GDIPlus_ImageAttributesDispose($hImageAttributes)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDisposeImageAttributes", "hwnd", $hImageAttributes)
If @error Then Return SetError(@error, @extended, False)
Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_ImageAttributesDispose