in _GetText() You used Return 4 times before cleaning resources
Func _GetText($iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $iNegative = 0, $iBorder = 0, $dScale = 1, $iBrightness = 0, $iContrast = 0, $sLanguageTagToUse = Default, $bUseOcrLine = False)
Local $hHBitmap, $hBitmap, $hGDIPlusBitmap, $hImage, $hImageCtxt, $sOCRTextResult, $iBmpW, $iBmpH, $iBorderColor
_GDIPlus_Startup()
$hHBitmap = _ScreenCapture_Capture("", $iLeft, $iTop, $iRight, $iBottom, False)
If @error Then
_GDIPlus_Shutdown()
Return SetError(1, 0, False)
EndIf
Local $tSIZE = _WinAPI_GetBitmapDimension($hHBitmap)
$iBmpW = $dScale * DllStructGetData($tSIZE, 'X')
$iBmpH = $dScale * DllStructGetData($tSIZE, 'Y')
;Default
;$iFlags=0,$iIlluminant=0,$iGammaR=10000,$iGammaG=10000,$iGammaB=10000,$iBlack=0,$iWhite=10000,$iContrast=0,$iBrightness=0,$iColorfulness=0,$iTint=0
Local $iIlluminant = 0, $iGammaR = 10000, $iGammaG = 10000, $iGammaB = 10000, $iBlack = 0, $iWhite = 10000, $iColorfulness = 0, $iTint = 0
Local $tAdj = 0
$tAdj = _WinAPI_CreateColorAdjustment($iNegative, $iIlluminant, $iGammaR, $iGammaG, $iGammaB, $iBlack, $iWhite, $iContrast, $iBrightness, $iColorfulness, $iTint)
$hBitmap = _WinAPI_AdjustBitmap($hHBitmap, $iBmpW, $iBmpH, $HALFTONE, $tAdj)
If @error Then
_GDIPlus_Shutdown()
Return SetError(2, 0, False)
EndIf
$hGDIPlusBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
; Add Border
If $iBorder > 0 Then
$iBorderColor = _GDIPlus_BitmapGetPixel($hGDIPlusBitmap, 1, 1) ;get pixel color from 1,1
$hImage = _GDIPlus_BitmapCreateFromScan0($iBmpW + (2 * $iBorder), $iBmpH + (2 * $iBorder)) ;create an empty bitmap
If @error Then
_GDIPlus_BitmapDispose($hGDIPlusBitmap)
_GDIPlus_Shutdown()
Return SetError(3, 0, False)
EndIf
$hImageCtxt = _GDIPlus_ImageGetGraphicsContext($hImage) ;get the graphics context of the bitmap
_GDIPlus_GraphicsSetSmoothingMode($hImageCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
_GDIPlus_GraphicsClear($hImageCtxt, $iBorderColor) ;clear bitmap with color white
_GDIPlus_GraphicsDrawImage($hImageCtxt, $hGDIPlusBitmap, $iBorder, $iBorder)
_GDIPlus_ImageDispose($hGDIPlusBitmap)
Else
$hImage = $hGDIPlusBitmap
EndIf
$sOCRTextResult = _UWPOCR_GetText($hImage, $sLanguageTagToUse, $bUseOcrLine)
Local $iError = @error
; Cleanup resources
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteObject($hHBitmap)
_GDIPlus_BitmapDispose($hImage)
_GDIPlus_BitmapDispose($hGDIPlusBitmap)
_GDIPlus_GraphicsDispose($hImageCtxt)
_GDIPlus_Shutdown()
Return SetError($iError = 0 ? 0 : 4, 0, $iError = 0 ? $sOCRTextResult : False)
EndFunc ;==>_GetText