corgano Posted September 20, 2013 Share Posted September 20, 2013 (edited) I have this function (can't remember where I got it) that returns the RGB of a pixel in a hImg Func _GDIPlus_BitmapGetPixel($hImage, $iX, $iY) Local $tArgb, $pArgb, $aRet $tArgb = DllStructCreate("dword Argb") $pArgb = DllStructGetPtr($tArgb) $aRet = DllCall($ghGDIPDll, "int", "GdipBitmapGetPixel", "hwnd", $hImage, "int", $iX, "int", $iY, "ptr", $pArgb) Return Hex(DllStructGetData($tArgb, "Argb"), 6) EndFunc It does the job, but every time it's called it uses more and more Memory. I'm not that familiar with DLLcalls, can anyone see where the leak is? More info: The first time I run it with a new image, my memory useage goes up y about 70mb. the images I am processing are about 500kb big. Makes no sense I can run it multiple times with the same file, with no change in memory usage? Edited September 20, 2013 by corgano 0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e Link to comment Share on other sites More sharing options...
UEZ Posted September 20, 2013 Share Posted September 20, 2013 Show the full code. I assume you forgot to dispose the bitmap in a loop.Br,UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
corgano Posted September 20, 2013 Author Share Posted September 20, 2013 Show the full code. I assume you forgot to dispose the bitmap in a loop. Br, UEZ That is exactly what I'm thinking, but I can't find it. Code is a bit long to dig through... although if anyone might find it interesting, you probably would It's a program to crop borders off of scanned documents / covers. It extracts images from a PDF (via Acrobat Pro) and then goes through each image, gets a bunch of sample points form the center of the image to find an average color, and then looks out form the center in all directions and pinpoints where the borders of that color - therefore the edges of that document - are, and then uses that info and the DPI to calculate the inches to crop off the sides. And it all works, the only issue is it climbs in memory as it goes through the images and rather rapidly at that To test it, just point the _filelistarray to a folder of images like this one '> expandcollapse popup$aFiles = _Filelisttoarray($ImgFolder,"*.jp?g",0) ;~ _ArrayDisplay($afiles) For $iPage = 0 to $aFiles[0]-1 $Jpg = $aFiles[$iPage+1] ;~ ConsoleWrite($iPage&" "&$aPages[$iPage][1]&" "&$aPages[$iPage][2]&" "&$Jpg&@CRLF) $hImage = _GDIPlus_ImageLoadFromFile($Jpg) $iWidth = _GDIPlus_ImageGetWidth( $hImage) $iHeight = _GDIPlus_ImageGetHeight($hImage) if $iWidth > $iHeight Then _GDIPlus_ImageRotateFlip($hImage, 1) $iWidth = _GDIPlus_ImageGetWidth( $hImage) $iHeight = _GDIPlus_ImageGetHeight($hImage) EndIf ;get the average color of the center area of the image $aColor = _GDIPlus_BitmapGetPixelAverage($hImage, "", "", 300, 15) ;Basic sensitivity calibration based on page contrast. Less contrast = more sensitave $t = 100-(((dec($aColor[1])+Dec($aColor[2])+dec($aColor[3]))/(3*2.55))/100*80) ;get the amount to crop each edge by $left = CropValue_Left($hImage, $aColor[0], $DPI, $iHeight/2, "", 10, $t) $right = ($iWidth/$DPI) - CropValue_Right($hImage, $aColor[0], $DPI, $iHeight/2, "", 10, $t) $bottom = ($iHeight/$DPI) - CropValue_Bottom($hImage, $aColor[0], $DPI, $iWidth/2, "", 10, $t) $top = CropValue_Top($hImage, $aColor[0], $DPI, $iWidth/2, "", 10, $t-10) ConsoleWrite(round($t,2)&" "&$aColor[0]&" "&$top&" "&$bottom&" "&$left&" "&$right&@CRLF) ;~ FileDelete($Jpg) _GDIPlus_ImageSaveToFileex($hImage, $Jpg&".mod.jpeg", _GDIPlus_EncodersGetCLSID("JPG")) _GDIPlus_ImageDispose($hImage) ;~ Exit Next Func pdfcroppage($oJSpdf, $spage = 0, $epage="q", $top=0, $bottom=0, $left=0, $right=0) if not IsInt($epage) then $epage = $spage $tBox = $oJSpdf.getPageBox("Crop", $spage); Dim $newBox[4] = [$left*72, $tBox[1]-($top*72), $tBox[2]-($right*72), +($bottom*72) ]; $oJSpdf.setPageBoxes("Crop", $spage, $epage, $newBox) EndFunc ;used to get some other data used in the script, ignore Func _ExcelGetBinders($iWave = "") $iWave = StringReplace($iWave, "Wave ", "") Local $list = "" Local $aRet[100][3] Local $oExcel = ObjCreate("Excel.Application") $oExcel.Visible = 0 $oExcel.WorkBooks.Open("J:\CNRL Scanning Project.xlsx") $oExcel.Worksheets("Thermal Databooks").Activate $iItem = 0 $oMatch = $oExcel.Cells.Find("Wave " & $iWave) If IsObj($oMatch) Then $sFirst = $oMatch.Address While IsObj($oMatch) $a = StringRegExp($oExcel.Cells($oMatch.Row, "K").value, "(?i)WAVE ? (\d?\d) ? - ? BOX ? (\d?\d)", 3) If IsArray($a) Then $aRet[$iItem][1] = $a[1] $aRet[$iItem][2] = StringTrimLeft( $oExcel.Cells($oMatch.Row, "D").Value, StringInStr( $oExcel.Cells($oMatch.Row, "D").Value, "_", 0, -1) ) $aRet[$iItem][0] = "Box "&$aRet[$iItem][1]&"\ "&$aRet[$iItem][2]&" Cover and Spine.pdf" $aRet[$iItem+1][1] = $a[1] $aRet[$iItem+1][2] = StringTrimLeft( $oExcel.Cells($oMatch.Row, "D").Value, StringInStr( $oExcel.Cells($oMatch.Row, "D").Value, "_", 0, -1) ) $aRet[$iItem+1][0] = "Box "&$aRet[$iItem][1]&"\ "&$aRet[$iItem][2]&" Cover and Spine.pdf" $iItem += 2 EndIf $oMatch = $oExcel.Cells.Findnext($oMatch) If $oMatch.Address = $sFirst Then ExitLoop WEnd EndIf ReDim $aRet[$iItem-1][3] Return $aRet EndFunc ;==>_ExcelGetBinders Func valuetoredgreen($num) $red = round(510-(2.55*$num*2)) $green = round(2.55*$num*2) if $red > 255 then $red = 255 if $green > 255 then $green = 255 ;~ ConsoleWrite($num&" "&$red&" "&$green&@CRLF) Return hex($red,2)&hex($green,2)&"00" EndFunc Func ColorCheckSim($c1, $c2) local $aDif[4], $a, $b for $i = 1 to 3 $a = dec(StringMid($c1,($i*2)-1,2)) $b = dec(StringMid($c2,($i*2)-1,2)) $aDif[$i] = 100 - (abs( $a - $b )/2.55) Next ;~ ConsoleWrite($aDif[1]&" "&$aDif[2]&" "&$aDif[3]&@CRLF) $aDif[0] = Round( ($aDif[1]+$aDif[2]+$aDif[3])/3 ,2) return $aDif EndFunc Func _GDIPlus_ImageRotateFlip($hImage, $iRotateFlipType) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipImageRotateFlip", "hwnd", $hImage, "int", $iRotateFlipType) If @error Then Return SetError(@error, @extended, False) $GDIP_STATUS = $aResult[0] Return $aResult[0] = 0 EndFunc ;==>_GDIPlus_ImageRotateFlip Func _GDIPlus_BitmapGetPixelAverage($hImage, $iX="", $iY="", $iDist = 100, $iPoints = 3) Local $i = 0, $pCenter[2], $aColor[$iPoints*$iPoints+1][4], $aAvg[4], $ret[4], $count = 0, $blackness, $Whiteness if $iY <> "" Then $pCenter[0] = $iX $pCenter[1] = $iY Else $pCenter[0] = _GDIPlus_ImageGetWidth($hImage)/2 $pCenter[1] = _GDIPlus_ImageGetHeight($hImage)/2 EndIf for $iX = $pCenter[0]-$iDist To $pCenter[0]+$iDist step $iDist/(($iPoints-1)/2) for $iY = $pCenter[1]-$iDist To $pCenter[1]+$iDist step $iDist/(($iPoints-1)/2) $i += 1 $aColor[$i][0] = _GDIPlus_BitmapGetPixel($hImage, $iX, $iY) $blackness = Round((Abs(dec("000000")-Dec($aColor[$i][0] ))/16777215),3)*100 $Whiteness = Round((Abs(dec("FFFFFF")-Dec($aColor[$i][0] ))/16777215),3)*100 ;~ ConsoleWrite($blackness&" ") if $blackness > 10 Then ;avoid adding black pixels to the average, gets more true color $count += 1 $aColor[$i][1] = StringLeft($aColor[$i][0],2) $aColor[$i][2] = StringMid($aColor[$i][0],3,2) $aColor[$i][3] = Stringright($aColor[$i][0],2) $aAvg[1] += Dec($aColor[$i][1]) $aAvg[2] += Dec($aColor[$i][2]) $aAvg[3] += Dec($aColor[$i][3]) EndIf ;~ ConsoleWrite($i&" "&$aColor[$i][0]&@CRLF) Next ;~ ConsoleWrite(@CRLF) Next $ret[1] = hex(Round($aAvg[1]/($count)),2) $ret[2] = hex(Round($aAvg[2]/($count)),2) $ret[3] = hex(Round($aAvg[3]/($count)),2) $ret[0] = $ret[1]&$ret[2]&$ret[3] $hPen = _GDIPlus_PenCreate("0xFF"&$ret[0],10) $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsDrawRect($hGraphics, $pCenter[0]-$iDist-5, $pCenter[1]-$iDist-5, $iDist*2+10, $iDist*2+10, $hPen) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphics) Return $ret EndFunc Func _GDIPlus_BitmapGetPixel($hImage, $iX, $iY) Local $tArgb, $pArgb, $aRet $tArgb = DllStructCreate("dword Argb") $pArgb = DllStructGetPtr($tArgb) $aRet = DllCall($ghGDIPDll, "int", "GdipBitmapGetPixel", "hwnd", $hImage, "int", $iX, "int", $iY, "ptr", $pArgb) Return Hex(DllStructGetData($tArgb, "Argb"), 6) EndFunc Func CropValue_Left($hImage, $Color, $DPI, $iY, $xStart = "", $samples = 10, $threashold = 80) Local $step, $iX, $count, $similarity, $iWidth = _GDIPlus_ImageGetWidth($hImage) Local $stack[5] = [100,100,100,100,100] $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) if $xStart = "" Then $xStart = $iWidth/2 ConsoleWrite("Left"&@CRLF) for $step = 0 to 100 step $samples $hPen = _GDIPlus_PenCreate("0xFF00FFFF",3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX, $iY + 10, $iX, $iY + 100, $hPen) _GDIPlus_PenDispose($hPen) if $step = 0 then $step = 1.5 for $iX = $xStart To 0 Step -$DPI/$step If $iX = 0 Then $xStart = round($iX + ( ($DPI/$step) * (UBound($stack)+1) ) ) $count = 0 $similarity = ColorCheckSim( $Color, _GDIPlus_BitmapGetPixel($hImage,$iX,$iY) ) $similarity2 = ColorCheckSim( "DDDDDD", _GDIPlus_BitmapGetPixel($hImage,$iX,$iY) ) $similarity = $similarity[0] ;~ ConsoleWrite(" "&$iX&" "&$similarity&" "&_GDIPlus_BitmapGetPixel($hImage,$iX,$iY)&" "&$Color&@CRLF) $hPen = _GDIPlus_PenCreate("0xFF"&valuetoredgreen($similarity*0.8),3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX, $iY - 10-(2*$step), $iX, $iY - 70-(2*$step), $hPen) _GDIPlus_PenDispose($hPen) if $similarity < $threashold and $similarity2[0] < 80 then $count += 1 for $i = UBound($stack)-1 to 1 step -1 if $stack[$i] < $threashold then $count += 1 $stack[$i] = $stack[$i-1] Next $stack[0] = $similarity ;~ ConsoleWrite($iX&" "&$stack[0]&" "&$stack[1]&" "&$stack[2]&" "&$stack[3]&" "&$stack[4]&@CRLF) If $count = UBound($stack) Then $xStart = round($iX + ( ($DPI/$step) * (UBound($stack)+1) ) ) ;~ ConsoleWrite("Back to "&$xStart&" with score "&Round( ( Abs( dec($aColor[1]) - Dec( _GDIPlus_BitmapGetPixel($hImage,$pCenter[0],$xStart) ) )/16777215 ) ,3)*100&@CRLF) ExitLoop EndIf Next if $step = 1.5 then $step = 0 Next $hPen = _GDIPlus_PenCreate("0xFFFFFF00",3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX, $iY + 100, $iX, $iY + 1000, $hPen) _GDIPlus_PenDispose($hPen) Return ($xStart-($DPI/$step*2) )/$DPI EndFunc Func CropValue_Right($hImage, $Color, $DPI, $iY, $xStart = "", $samples = 10, $threashold = 80) Local $step, $iX, $count, $similarity, $iWidth = _GDIPlus_ImageGetWidth($hImage) Local $stack[5] = [100,100,100,100,100] $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) if $xStart = "" Then $xStart = $iWidth/2 ConsoleWrite("Right"&@CRLF) for $step = 0 to 100 step $samples $hPen = _GDIPlus_PenCreate("0xFF00FFFF",3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX, $iY + 10, $iX, $iY + 100, $hPen) _GDIPlus_PenDispose($hPen) if $step = 0 then $step = 1.5 for $iX = $xStart To $iWidth Step +$DPI/$step If $iX >= $iWidth-($DPI/$Step) Then $xStart = round($iX - ( ($DPI/$step) * (UBound($stack)+1) ) ) $count = 0 $similarity2 = ColorCheckSim( "DDDDDD", _GDIPlus_BitmapGetPixel($hImage,$iX,$iY) ) $similarity = ColorCheckSim( $Color, _GDIPlus_BitmapGetPixel($hImage,$iX,$iY) ) ;~ ConsoleWrite(" "&$iX&" "&$similarity[0]&" "&_GDIPlus_BitmapGetPixel($hImage,$iX,$iY)&" "&$Color&@CRLF) $hPen = _GDIPlus_PenCreate("0xFF"&valuetoredgreen($similarity[0]*0.8),3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX, $iY - 10-(2*$step), $iX, $iY - 70-(2*$step), $hPen) _GDIPlus_PenDispose($hPen) if ($similarity[0] < $threashold or $similarity[3] < $threashold) and $similarity2[0] < 80 then $count += 1 for $i = UBound($stack)-1 to 1 step -1 if $stack[$i] < $threashold then $count += 1 $stack[$i] = $stack[$i-1] Next $stack[0] = $similarity[0] ;~ ConsoleWrite(Round($iX)&" "&$stack[0]&" "&$stack[1]&" "&$stack[2]&" "&$stack[3]&" "&$stack[4]&@CRLF) If $count = UBound($stack) Then $xStart = round($iX - ( ($DPI/$step) * (UBound($stack)+1) ) ) ;~ ConsoleWrite("Back to "&$xStart&" with score "&Round( ( Abs( dec($aColor[1]) - Dec( _GDIPlus_BitmapGetPixel($hImage,$pCenter[0],$xStart) ) )/16777215 ) ,3)*100&@CRLF) ExitLoop EndIf Next if $step = 1.5 then $step = 0 Next $hPen = _GDIPlus_PenCreate("0xFFFFFF00",3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX, $iY + 100, $iX, $iY + 1000, $hPen) _GDIPlus_PenDispose($hPen) Return ($xStart-($DPI/$step*2) )/$DPI EndFunc Func CropValue_Bottom($hImage, $Color, $DPI, $iX, $yStart = "", $samples = 10, $threashold = 80) Local $step, $iY, $count, $similarity, $iHeight = _GDIPlus_ImageGetHeight($hImage) Local $stack[5] = [100,100,100,100,100] $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) if $yStart = "" Then $yStart = $iHeight/2 $similarity = ColorCheckSim( $Color, _GDIPlus_BitmapGetPixel($hImage,$iX,$yStart) ) if $similarity[0] < 20 Then $iX -= $DPI $similarity = ColorCheckSim( $Color, _GDIPlus_BitmapGetPixel($hImage,$iX,$yStart) ) if $similarity[0] < 20 Then $iX += ($DPI*2) $similarity = ColorCheckSim( $Color, _GDIPlus_BitmapGetPixel($hImage,$iX,$yStart) ) if $similarity[0] < 20 Then return 0 EndIf EndIf EndIf ConsoleWrite("Bottom"&@CRLF) for $step = 0 to 100 step $samples $hPen = _GDIPlus_PenCreate("0xFF00FFFF",3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX + 10, $iY, $iX + 100, $iY, $hPen) _GDIPlus_PenDispose($hPen) if $step = 0 then $step = 1.5 for $iY = $yStart To $iHeight Step +$DPI/$step If $iY = 0 Then $yStart = round($iX - ( ($DPI/$step) * (UBound($stack)+1) ) ) $count = 0 $similarity = ColorCheckSim( $Color, _GDIPlus_BitmapGetPixel($hImage,$iX,$iY) ) $similarity2 = ColorCheckSim( "DDDDDD", _GDIPlus_BitmapGetPixel($hImage,$iX,$iY) ) $similarity = $similarity[0] ;~ ConsoleWrite(" "&$iX&" "&$similarity&" "&_GDIPlus_BitmapGetPixel($hImage,$iX,$iY)&" "&$Color&@CRLF) $hPen = _GDIPlus_PenCreate("0xFF"&valuetoredgreen($similarity*0.8),3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX - 10-(2*$step), $iY, $iX - 70-(2*$step), $iY, $hPen) _GDIPlus_PenDispose($hPen) if $similarity < $threashold and $similarity2[0] < 80 then $count += 1 for $i = UBound($stack)-1 to 1 step -1 if $stack[$i] < $threashold then $count += 1 $stack[$i] = $stack[$i-1] Next $stack[0] = $similarity ;~ ConsoleWrite($iY&" "&$stack[0]&" "&$stack[1]&" "&$stack[2]&" "&$stack[3]&" "&$stack[4]&@CRLF) If $count = UBound($stack) Then $yStart = round($iY - ( ($DPI/$step) * (UBound($stack)+1) ) ) ;~ ConsoleWrite("Back to "&$yStart&" with score "&Round( ( Abs( dec($aColor[1]) - Dec( _GDIPlus_BitmapGetPixel($hImage,$pCenter[0],$yStart) ) )/16777215 ) ,3)*100&@CRLF) ExitLoop EndIf Next if $step = 1.5 then $step = 0 Next $hPen = _GDIPlus_PenCreate("0xFFFFFF00",3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX + 100, $iY, $iX + 1000, $iY, $hPen) _GDIPlus_PenDispose($hPen) Return ($yStart-($DPI/$step*2) )/$DPI EndFunc Func CropValue_Top($hImage, $Color, $DPI, $iX, $yStart = "", $samples = 10, $threashold = 80) Local $step, $iY, $count, $similarity, $iHeight = _GDIPlus_ImageGetHeight($hImage) Local $stack[5] = [100,100,100,100,100] $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) if $yStart = "" Then $yStart = $iHeight/2 $similarity = ColorCheckSim( $Color, _GDIPlus_BitmapGetPixel($hImage,$iX,$yStart) ) if $similarity[0] < 20 Then $iX -= $DPI $similarity = ColorCheckSim( $Color, _GDIPlus_BitmapGetPixel($hImage,$iX,$yStart) ) if $similarity[0] < 20 Then $iX += ($DPI*2) $similarity = ColorCheckSim( $Color, _GDIPlus_BitmapGetPixel($hImage,$iX,$yStart) ) if $similarity[0] < 20 Then return 0 EndIf EndIf EndIf ConsoleWrite("Top"&@CRLF) for $step = 0 to 100 step $samples $hPen = _GDIPlus_PenCreate("0xFF00FFFF",3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX + 10, $iY, $iX + 100, $iY, $hPen) _GDIPlus_PenDispose($hPen) if $step = 0 then $step = 1.5 for $iY = $yStart To 0 Step -$DPI/$step If $iY < $DPI/$step Then $yStart = round($iY + ( ($DPI/$step) * (UBound($stack)+1) ) ) $count = 0 $similarity = ColorCheckSim( $Color, _GDIPlus_BitmapGetPixel($hImage,$iX,$iY) ) $similarity2 = ColorCheckSim( "DDDDDD", _GDIPlus_BitmapGetPixel($hImage,$iX,$iY) ) $similarity = $similarity[0] ;~ ConsoleWrite(" "&$iX&" "&$similarity&" "&_GDIPlus_BitmapGetPixel($hImage,$iX,$iY)&" "&$Color&@CRLF) $hPen = _GDIPlus_PenCreate("0xFF"&valuetoredgreen($similarity*0.8),3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX - 10-(2*$step), $iY, $iX - 70-(2*$step), $iY, $hPen) _GDIPlus_PenDispose($hPen) if $similarity < $threashold and $similarity2[0] < 80 then $count += 1 for $i = UBound($stack)-1 to 1 step -1 if $stack[$i] < $threashold then $count += 1 $stack[$i] = $stack[$i-1] Next $stack[0] = $similarity ;~ ConsoleWrite($iY&" "&$stack[0]&" "&$stack[1]&" "&$stack[2]&" "&$stack[3]&" "&$stack[4]&@CRLF) If $count = UBound($stack) Then $yStart = round($iY + ( ($DPI/$step) * (UBound($stack)+1) ) ) ;~ ConsoleWrite("Back to "&$yStart&" with score "&Round( ( Abs( dec($aColor[1]) - Dec( _GDIPlus_BitmapGetPixel($hImage,$pCenter[0],$yStart) ) )/16777215 ) ,3)*100&@CRLF) ExitLoop EndIf Next if $step = 1.5 then $step = 0 Next $hPen = _GDIPlus_PenCreate("0xFFFFFF00",3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX + 100, $iY, $iX + 1000, $iY, $hPen) _GDIPlus_PenDispose($hPen) Return ($yStart-($DPI/$step*2) )/$DPI EndFunc 0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e Link to comment Share on other sites More sharing options...
UEZ Posted September 20, 2013 Share Posted September 20, 2013 Can you try this? expandcollapse popup$aFiles = _FileListToArray($ImgFolder, "*.jp?g", 0) ;~ _ArrayDisplay($afiles) For $iPage = 0 To $aFiles[0] - 1 $Jpg = $aFiles[$iPage + 1] ;~ ConsoleWrite($iPage&" "&$aPages[$iPage][1]&" "&$aPages[$iPage][2]&" "&$Jpg&@CRLF) $hImage = _GDIPlus_ImageLoadFromFile($Jpg) $iWidth = _GDIPlus_ImageGetWidth($hImage) $iHeight = _GDIPlus_ImageGetHeight($hImage) If $iWidth > $iHeight Then _GDIPlus_ImageRotateFlip($hImage, 1) $iWidth = _GDIPlus_ImageGetWidth($hImage) $iHeight = _GDIPlus_ImageGetHeight($hImage) EndIf ;get the average color of the center area of the image $aColor = _GDIPlus_BitmapGetPixelAverage($hImage, "", "", 300, 15) ;Basic sensitivity calibration based on page contrast. Less contrast = more sensitave $t = 100 - (((Dec($aColor[1]) + Dec($aColor[2]) + Dec($aColor[3])) / (3 * 2.55)) / 100 * 80) ;get the amount to crop each edge by $left = CropValue_Left($hImage, $aColor[0], $DPI, $iHeight / 2, "", 10, $t) $right = ($iWidth / $DPI) - CropValue_Right($hImage, $aColor[0], $DPI, $iHeight / 2, "", 10, $t) $bottom = ($iHeight / $DPI) - CropValue_Bottom($hImage, $aColor[0], $DPI, $iWidth / 2, "", 10, $t) $top = CropValue_Top($hImage, $aColor[0], $DPI, $iWidth / 2, "", 10, $t - 10) ConsoleWrite(Round($t, 2) & " " & $aColor[0] & " " & $top & " " & $bottom & " " & $left & " " & $right & @CRLF) ;~ FileDelete($Jpg) _GDIPlus_ImageSaveToFileEx($hImage, $Jpg & ".mod.jpeg", _GDIPlus_EncodersGetCLSID("JPG")) _GDIPlus_ImageDispose($hImage) ;~ Exit Next Func pdfcroppage($oJSpdf, $spage = 0, $epage = "q", $top = 0, $bottom = 0, $left = 0, $right = 0) If Not IsInt($epage) Then $epage = $spage $tBox = $oJSpdf.getPageBox("Crop", $spage); Dim $newBox[4] = [$left * 72, $tBox[1] - ($top * 72), $tBox[2] - ($right * 72), +($bottom * 72)]; $oJSpdf.setPageBoxes("Crop", $spage, $epage, $newBox) EndFunc ;==>pdfcroppage ;used to get some other data used in the script, ignore Func _ExcelGetBinders($iWave = "") $iWave = StringReplace($iWave, "Wave ", "") Local $list = "" Local $aRet[100][3] Local $oExcel = ObjCreate("Excel.Application") $oExcel.Visible = 0 $oExcel.WorkBooks.Open("J:\CNRL Scanning Project.xlsx") $oExcel.Worksheets("Thermal Databooks").Activate $iItem = 0 $oMatch = $oExcel.Cells.Find("Wave " & $iWave) If IsObj($oMatch) Then $sFirst = $oMatch.Address While IsObj($oMatch) $a = StringRegExp($oExcel.Cells($oMatch.Row, "K").value, "(?i)WAVE ? (\d?\d) ? - ? BOX ? (\d?\d)", 3) If IsArray($a) Then $aRet[$iItem][1] = $a[1] $aRet[$iItem][2] = StringTrimLeft($oExcel.Cells($oMatch.Row, "D").Value, StringInStr($oExcel.Cells($oMatch.Row, "D").Value, "_", 0, -1)) $aRet[$iItem][0] = "Box " & $aRet[$iItem][1] & "\ " & $aRet[$iItem][2] & " Cover and Spine.pdf" $aRet[$iItem + 1][1] = $a[1] $aRet[$iItem + 1][2] = StringTrimLeft($oExcel.Cells($oMatch.Row, "D").Value, StringInStr($oExcel.Cells($oMatch.Row, "D").Value, "_", 0, -1)) $aRet[$iItem + 1][0] = "Box " & $aRet[$iItem][1] & "\ " & $aRet[$iItem][2] & " Cover and Spine.pdf" $iItem += 2 EndIf $oMatch = $oExcel.Cells.Findnext($oMatch) If $oMatch.Address = $sFirst Then ExitLoop WEnd EndIf ReDim $aRet[$iItem - 1][3] Return $aRet EndFunc ;==>_ExcelGetBinders Func valuetoredgreen($num) $red = Round(510 - (2.55 * $num * 2)) $green = Round(2.55 * $num * 2) If $red > 255 Then $red = 255 If $green > 255 Then $green = 255 ;~ ConsoleWrite($num&" "&$red&" "&$green&@CRLF) Return Hex($red, 2) & Hex($green, 2) & "00" EndFunc ;==>valuetoredgreen Func ColorCheckSim($c1, $c2) Local $aDif[4], $a, $b For $i = 1 To 3 $a = Dec(StringMid($c1, ($i * 2) - 1, 2)) $b = Dec(StringMid($c2, ($i * 2) - 1, 2)) $aDif[$i] = 100 - (Abs($a - $b) / 2.55) Next ;~ ConsoleWrite($aDif[1]&" "&$aDif[2]&" "&$aDif[3]&@CRLF) $aDif[0] = Round(($aDif[1] + $aDif[2] + $aDif[3]) / 3, 2) Return $aDif EndFunc ;==>ColorCheckSim Func _GDIPlus_ImageRotateFlip($hImage, $iRotateFlipType) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipImageRotateFlip", "hwnd", $hImage, "int", $iRotateFlipType) If @error Then Return SetError(@error, @extended, False) $GDIP_STATUS = $aResult[0] Return $aResult[0] = 0 EndFunc ;==>_GDIPlus_ImageRotateFlip Func _GDIPlus_BitmapGetPixelAverage($hImage, $iX = "", $iY = "", $iDist = 100, $iPoints = 3) Local $i = 0, $pCenter[2], $aColor[$iPoints * $iPoints + 1][4], $aAvg[4], $ret[4], $count = 0, $blackness, $Whiteness If $iY <> "" Then $pCenter[0] = $iX $pCenter[1] = $iY Else $pCenter[0] = _GDIPlus_ImageGetWidth($hImage) / 2 $pCenter[1] = _GDIPlus_ImageGetHeight($hImage) / 2 EndIf For $iX = $pCenter[0] - $iDist To $pCenter[0] + $iDist Step $iDist / (($iPoints - 1) / 2) For $iY = $pCenter[1] - $iDist To $pCenter[1] + $iDist Step $iDist / (($iPoints - 1) / 2) $i += 1 $aColor[$i][0] = _GDIPlus_BitmapGetPixel($hImage, $iX, $iY) $blackness = Round((Abs(Dec("000000") - Dec($aColor[$i][0])) / 16777215), 3) * 100 $Whiteness = Round((Abs(Dec("FFFFFF") - Dec($aColor[$i][0])) / 16777215), 3) * 100 ;~ ConsoleWrite($blackness&" ") If $blackness > 10 Then ;avoid adding black pixels to the average, gets more true color $count += 1 $aColor[$i][1] = StringLeft($aColor[$i][0], 2) $aColor[$i][2] = StringMid($aColor[$i][0], 3, 2) $aColor[$i][3] = StringRight($aColor[$i][0], 2) $aAvg[1] += Dec($aColor[$i][1]) $aAvg[2] += Dec($aColor[$i][2]) $aAvg[3] += Dec($aColor[$i][3]) EndIf ;~ ConsoleWrite($i&" "&$aColor[$i][0]&@CRLF) Next ;~ ConsoleWrite(@CRLF) Next $ret[1] = Hex(Round($aAvg[1] / ($count)), 2) $ret[2] = Hex(Round($aAvg[2] / ($count)), 2) $ret[3] = Hex(Round($aAvg[3] / ($count)), 2) $ret[0] = $ret[1] & $ret[2] & $ret[3] $hPen = _GDIPlus_PenCreate("0xFF" & $ret[0], 10) $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsDrawRect($hGraphics, $pCenter[0] - $iDist - 5, $pCenter[1] - $iDist - 5, $iDist * 2 + 10, $iDist * 2 + 10, $hPen) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphics) Return $ret EndFunc ;==>_GDIPlus_BitmapGetPixelAverage Func _GDIPlus_BitmapGetPixel($hImage, $iX, $iY) Local $tArgb, $pArgb, $aRet $tArgb = DllStructCreate("dword Argb") $pArgb = DllStructGetPtr($tArgb) $aRet = DllCall($ghGDIPDll, "int", "GdipBitmapGetPixel", "hwnd", $hImage, "int", $iX, "int", $iY, "ptr", $pArgb) Return Hex(DllStructGetData($tArgb, "Argb"), 6) EndFunc ;==>_GDIPlus_BitmapGetPixel Func CropValue_Left($hImage, $Color, $DPI, $iY, $xStart = "", $samples = 10, $threashold = 80) Local $step, $iX, $count, $similarity, $iWidth = _GDIPlus_ImageGetWidth($hImage) Local $stack[5] = [100, 100, 100, 100, 100] $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) If $xStart = "" Then $xStart = $iWidth / 2 ConsoleWrite("Left" & @CRLF) For $step = 0 To 100 Step $samples $hPen = _GDIPlus_PenCreate("0xFF00FFFF", 3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX, $iY + 10, $iX, $iY + 100, $hPen) _GDIPlus_PenDispose($hPen) If $step = 0 Then $step = 1.5 For $iX = $xStart To 0 Step -$DPI / $step If $iX = 0 Then $xStart = Round($iX + (($DPI / $step) * (UBound($stack) + 1))) $count = 0 $similarity = ColorCheckSim($Color, _GDIPlus_BitmapGetPixel($hImage, $iX, $iY)) $similarity2 = ColorCheckSim("DDDDDD", _GDIPlus_BitmapGetPixel($hImage, $iX, $iY)) $similarity = $similarity[0] ;~ ConsoleWrite(" "&$iX&" "&$similarity&" "&_GDIPlus_BitmapGetPixel($hImage,$iX,$iY)&" "&$Color&@CRLF) $hPen = _GDIPlus_PenCreate("0xFF" & valuetoredgreen($similarity * 0.8), 3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX, $iY - 10 - (2 * $step), $iX, $iY - 70 - (2 * $step), $hPen) _GDIPlus_PenDispose($hPen) If $similarity < $threashold And $similarity2[0] < 80 Then $count += 1 For $i = UBound($stack) - 1 To 1 Step -1 If $stack[$i] < $threashold Then $count += 1 $stack[$i] = $stack[$i - 1] Next $stack[0] = $similarity ;~ ConsoleWrite($iX&" "&$stack[0]&" "&$stack[1]&" "&$stack[2]&" "&$stack[3]&" "&$stack[4]&@CRLF) If $count = UBound($stack) Then $xStart = Round($iX + (($DPI / $step) * (UBound($stack) + 1))) ;~ ConsoleWrite("Back to "&$xStart&" with score "&Round( ( Abs( dec($aColor[1]) - Dec( _GDIPlus_BitmapGetPixel($hImage,$pCenter[0],$xStart) ) )/16777215 ) ,3)*100&@CRLF) ExitLoop EndIf Next If $step = 1.5 Then $step = 0 Next $hPen = _GDIPlus_PenCreate("0xFFFFFF00", 3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX, $iY + 100, $iX, $iY + 1000, $hPen) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphics) Return ($xStart - ($DPI / $step * 2)) / $DPI EndFunc ;==>CropValue_Left Func CropValue_Right($hImage, $Color, $DPI, $iY, $xStart = "", $samples = 10, $threashold = 80) Local $step, $iX, $count, $similarity, $iWidth = _GDIPlus_ImageGetWidth($hImage) Local $stack[5] = [100, 100, 100, 100, 100] $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) If $xStart = "" Then $xStart = $iWidth / 2 ConsoleWrite("Right" & @CRLF) For $step = 0 To 100 Step $samples $hPen = _GDIPlus_PenCreate("0xFF00FFFF", 3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX, $iY + 10, $iX, $iY + 100, $hPen) _GDIPlus_PenDispose($hPen) If $step = 0 Then $step = 1.5 For $iX = $xStart To $iWidth Step +$DPI / $step If $iX >= $iWidth - ($DPI / $step) Then $xStart = Round($iX - (($DPI / $step) * (UBound($stack) + 1))) $count = 0 $similarity2 = ColorCheckSim("DDDDDD", _GDIPlus_BitmapGetPixel($hImage, $iX, $iY)) $similarity = ColorCheckSim($Color, _GDIPlus_BitmapGetPixel($hImage, $iX, $iY)) ;~ ConsoleWrite(" "&$iX&" "&$similarity[0]&" "&_GDIPlus_BitmapGetPixel($hImage,$iX,$iY)&" "&$Color&@CRLF) $hPen = _GDIPlus_PenCreate("0xFF" & valuetoredgreen($similarity[0] * 0.8), 3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX, $iY - 10 - (2 * $step), $iX, $iY - 70 - (2 * $step), $hPen) _GDIPlus_PenDispose($hPen) If ($similarity[0] < $threashold Or $similarity[3] < $threashold) And $similarity2[0] < 80 Then $count += 1 For $i = UBound($stack) - 1 To 1 Step -1 If $stack[$i] < $threashold Then $count += 1 $stack[$i] = $stack[$i - 1] Next $stack[0] = $similarity[0] ;~ ConsoleWrite(Round($iX)&" "&$stack[0]&" "&$stack[1]&" "&$stack[2]&" "&$stack[3]&" "&$stack[4]&@CRLF) If $count = UBound($stack) Then $xStart = Round($iX - (($DPI / $step) * (UBound($stack) + 1))) ;~ ConsoleWrite("Back to "&$xStart&" with score "&Round( ( Abs( dec($aColor[1]) - Dec( _GDIPlus_BitmapGetPixel($hImage,$pCenter[0],$xStart) ) )/16777215 ) ,3)*100&@CRLF) ExitLoop EndIf Next If $step = 1.5 Then $step = 0 Next $hPen = _GDIPlus_PenCreate("0xFFFFFF00", 3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX, $iY + 100, $iX, $iY + 1000, $hPen) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphics) Return ($xStart - ($DPI / $step * 2)) / $DPI EndFunc ;==>CropValue_Right Func CropValue_Bottom($hImage, $Color, $DPI, $iX, $yStart = "", $samples = 10, $threashold = 80) Local $step, $iY, $count, $similarity, $iHeight = _GDIPlus_ImageGetHeight($hImage) Local $stack[5] = [100, 100, 100, 100, 100] $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) If $yStart = "" Then $yStart = $iHeight / 2 $similarity = ColorCheckSim($Color, _GDIPlus_BitmapGetPixel($hImage, $iX, $yStart)) If $similarity[0] < 20 Then $iX -= $DPI $similarity = ColorCheckSim($Color, _GDIPlus_BitmapGetPixel($hImage, $iX, $yStart)) If $similarity[0] < 20 Then $iX += ($DPI * 2) $similarity = ColorCheckSim($Color, _GDIPlus_BitmapGetPixel($hImage, $iX, $yStart)) If $similarity[0] < 20 Then Return 0 EndIf EndIf EndIf ConsoleWrite("Bottom" & @CRLF) For $step = 0 To 100 Step $samples $hPen = _GDIPlus_PenCreate("0xFF00FFFF", 3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX + 10, $iY, $iX + 100, $iY, $hPen) _GDIPlus_PenDispose($hPen) If $step = 0 Then $step = 1.5 For $iY = $yStart To $iHeight Step +$DPI / $step If $iY = 0 Then $yStart = Round($iX - (($DPI / $step) * (UBound($stack) + 1))) $count = 0 $similarity = ColorCheckSim($Color, _GDIPlus_BitmapGetPixel($hImage, $iX, $iY)) $similarity2 = ColorCheckSim("DDDDDD", _GDIPlus_BitmapGetPixel($hImage, $iX, $iY)) $similarity = $similarity[0] ;~ ConsoleWrite(" "&$iX&" "&$similarity&" "&_GDIPlus_BitmapGetPixel($hImage,$iX,$iY)&" "&$Color&@CRLF) $hPen = _GDIPlus_PenCreate("0xFF" & valuetoredgreen($similarity * 0.8), 3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX - 10 - (2 * $step), $iY, $iX - 70 - (2 * $step), $iY, $hPen) _GDIPlus_PenDispose($hPen) If $similarity < $threashold And $similarity2[0] < 80 Then $count += 1 For $i = UBound($stack) - 1 To 1 Step -1 If $stack[$i] < $threashold Then $count += 1 $stack[$i] = $stack[$i - 1] Next $stack[0] = $similarity ;~ ConsoleWrite($iY&" "&$stack[0]&" "&$stack[1]&" "&$stack[2]&" "&$stack[3]&" "&$stack[4]&@CRLF) If $count = UBound($stack) Then $yStart = Round($iY - (($DPI / $step) * (UBound($stack) + 1))) ;~ ConsoleWrite("Back to "&$yStart&" with score "&Round( ( Abs( dec($aColor[1]) - Dec( _GDIPlus_BitmapGetPixel($hImage,$pCenter[0],$yStart) ) )/16777215 ) ,3)*100&@CRLF) ExitLoop EndIf Next If $step = 1.5 Then $step = 0 Next $hPen = _GDIPlus_PenCreate("0xFFFFFF00", 3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX + 100, $iY, $iX + 1000, $iY, $hPen) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphics) Return ($yStart - ($DPI / $step * 2)) / $DPI EndFunc ;==>CropValue_Bottom Func CropValue_Top($hImage, $Color, $DPI, $iX, $yStart = "", $samples = 10, $threashold = 80) Local $step, $iY, $count, $similarity, $iHeight = _GDIPlus_ImageGetHeight($hImage) Local $stack[5] = [100, 100, 100, 100, 100] $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) If $yStart = "" Then $yStart = $iHeight / 2 $similarity = ColorCheckSim($Color, _GDIPlus_BitmapGetPixel($hImage, $iX, $yStart)) If $similarity[0] < 20 Then $iX -= $DPI $similarity = ColorCheckSim($Color, _GDIPlus_BitmapGetPixel($hImage, $iX, $yStart)) If $similarity[0] < 20 Then $iX += ($DPI * 2) $similarity = ColorCheckSim($Color, _GDIPlus_BitmapGetPixel($hImage, $iX, $yStart)) If $similarity[0] < 20 Then Return 0 EndIf EndIf EndIf ConsoleWrite("Top" & @CRLF) For $step = 0 To 100 Step $samples $hPen = _GDIPlus_PenCreate("0xFF00FFFF", 3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX + 10, $iY, $iX + 100, $iY, $hPen) _GDIPlus_PenDispose($hPen) If $step = 0 Then $step = 1.5 For $iY = $yStart To 0 Step -$DPI / $step If $iY < $DPI / $step Then $yStart = Round($iY + (($DPI / $step) * (UBound($stack) + 1))) $count = 0 $similarity = ColorCheckSim($Color, _GDIPlus_BitmapGetPixel($hImage, $iX, $iY)) $similarity2 = ColorCheckSim("DDDDDD", _GDIPlus_BitmapGetPixel($hImage, $iX, $iY)) $similarity = $similarity[0] ;~ ConsoleWrite(" "&$iX&" "&$similarity&" "&_GDIPlus_BitmapGetPixel($hImage,$iX,$iY)&" "&$Color&@CRLF) $hPen = _GDIPlus_PenCreate("0xFF" & valuetoredgreen($similarity * 0.8), 3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX - 10 - (2 * $step), $iY, $iX - 70 - (2 * $step), $iY, $hPen) _GDIPlus_PenDispose($hPen) If $similarity < $threashold And $similarity2[0] < 80 Then $count += 1 For $i = UBound($stack) - 1 To 1 Step -1 If $stack[$i] < $threashold Then $count += 1 $stack[$i] = $stack[$i - 1] Next $stack[0] = $similarity ;~ ConsoleWrite($iY&" "&$stack[0]&" "&$stack[1]&" "&$stack[2]&" "&$stack[3]&" "&$stack[4]&@CRLF) If $count = UBound($stack) Then $yStart = Round($iY + (($DPI / $step) * (UBound($stack) + 1))) ;~ ConsoleWrite("Back to "&$yStart&" with score "&Round( ( Abs( dec($aColor[1]) - Dec( _GDIPlus_BitmapGetPixel($hImage,$pCenter[0],$yStart) ) )/16777215 ) ,3)*100&@CRLF) ExitLoop EndIf Next If $step = 1.5 Then $step = 0 Next $hPen = _GDIPlus_PenCreate("0xFFFFFF00", 3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX + 100, $iY, $iX + 1000, $iY, $hPen) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphics) Return ($yStart - ($DPI / $step * 2)) / $DPI EndFunc ;==>CropValue_Top I added several _GDIPlus_GraphicsDispose($hGraphics) lines within the functions. Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
corgano Posted September 20, 2013 Author Share Posted September 20, 2013 (edited) am I really that dumb? Yes I am! Thankyou very much ....I even thought of that, and went through and made sure each one had a _GDIPlus_GraphicsDispose. I must have just missed a few (read:lot) of them If you're not busy, I have another question. With the functions that find the abount to crop on each side, they are all very similar: in fact, the only thing that changes is the direction (adding or subtracting) and the axis (whether it's changing the x or y). I know it should be possible to tell it which side to do and figure out which axis and direction to go, so i could use one function for all 4 directions, but I just can't wrap my mind around it... Maybe you and your superior brain could give it a try? expandcollapse popupFunc CropValue_Left($hImage, $Color, $DPI, $iY, $xStart = "", $samples = 10, $threashold = 80) Local $step, $iX, $count, $similarity, $iWidth = _GDIPlus_ImageGetWidth($hImage) Local $stack[5] = [100, 100, 100, 100, 100] $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) If $xStart = "" Then $xStart = $iWidth / 2 ConsoleWrite("Left" & @CRLF) For $step = 0 To 100 Step $samples $hPen = _GDIPlus_PenCreate("0xFF00FFFF", 3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX, $iY + 10, $iX, $iY + 100, $hPen) _GDIPlus_PenDispose($hPen) If $step = 0 Then $step = 1.5 For $iX = $xStart To 0 Step -$DPI / $step If $iX = 0 Then $xStart = Round($iX + (($DPI / $step) * (UBound($stack) + 1))) $count = 0 $similarity = ColorCheckSim($Color, _GDIPlus_BitmapGetPixel($hImage, $iX, $iY)) $similarity2 = ColorCheckSim("DDDDDD", _GDIPlus_BitmapGetPixel($hImage, $iX, $iY)) $similarity = $similarity[0] ;~ ConsoleWrite(" "&$iX&" "&$similarity&" "&_GDIPlus_BitmapGetPixel($hImage,$iX,$iY)&" "&$Color&@CRLF) $hPen = _GDIPlus_PenCreate("0xFF" & valuetoredgreen($similarity * 0.8), 3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX, $iY - 10 - (2 * $step), $iX, $iY - 70 - (2 * $step), $hPen) _GDIPlus_PenDispose($hPen) If $similarity < $threashold And $similarity2[0] < 80 Then $count += 1 For $i = UBound($stack) - 1 To 1 Step -1 If $stack[$i] < $threashold Then $count += 1 $stack[$i] = $stack[$i - 1] Next $stack[0] = $similarity ;~ ConsoleWrite($iX&" "&$stack[0]&" "&$stack[1]&" "&$stack[2]&" "&$stack[3]&" "&$stack[4]&@CRLF) If $count = UBound($stack) Then $xStart = Round($iX + (($DPI / $step) * (UBound($stack) + 1))) ;~ ConsoleWrite("Back to "&$xStart&" with score "&Round( ( Abs( dec($aColor[1]) - Dec( _GDIPlus_BitmapGetPixel($hImage,$pCenter[0],$xStart) ) )/16777215 ) ,3)*100&@CRLF) ExitLoop EndIf Next If $step = 1.5 Then $step = 0 Next $hPen = _GDIPlus_PenCreate("0xFFFFFF00", 3) _GDIPlus_GraphicsDrawLine($hGraphics, $iX, $iY + 100, $iX, $iY + 1000, $hPen) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphics) Return ($xStart - ($DPI / $step * 2)) / $DPI EndFunc ;==>CropValue_Left Added example input and output, so explanations make sense. Also made the question make sense Edited September 20, 2013 by corgano 0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now