Is it possible to capture only the color you want in the gdip library capture tool?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
glskzks7
Posts: 2
Joined: 10 May 2020, 20:14

Is it possible to capture only the color you want in the gdip library capture tool?

31 May 2021, 20:58

I am using the gdip library
But this capture tool captures and saves all colors in the area I specified.

ex)

Code: Select all

F3::
	FileDelete,Result.png
	Sleep,250
	pToken := Gdip_StartUp()
	pBitmap := Gdip_BitmapFromScreen("200|200|500|500")
	Gdip_SaveBitmapToFile(pBitmap, "C:\Users\Administrator\Documents\Result.png")
	Gdip_DisposeImage(pBitmap)
	Gdip_Shutdown(pToken)
Return
[Mod edit: [code][/code] tags added.]

Q1) Is it possible to modify the gdip library to only capture black?
Q2) What function should I fix when I want to extract black or only the color I want to capture?

thank you i wish you always happy! :D
sooyke_
Posts: 25
Joined: 18 Nov 2020, 10:27

Re: Is it possible to capture only the color you want in the gdip library capture tool?

03 Jun 2021, 07:06

I guess the only thing you can do is to replace the colors different than black . If you are using it for text extraction then this will not work because text contains a variation of greys and little real black color .

Just to try it out :

Code: Select all


f3::

If !pToken := Gdip_Startup()
  {
    MsgBox, 48, gdiplus Error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
    ExitApp
  }
setworkingdir , %a_scriptdir% 
pBitmap :=Gdip_CreateBitmapFromClipboard()
color_filter(pBitmap,0xff000000,0xffffffff)
Gdip_SaveBitmapToFile(pBitmap, a_now ".png")
return

esc::exitapp

color_filter(pBitmap,color_keep,color_replace){
    
Gdip_GetImageDimensions(pBitmap,w,h)
    If Gdip_LockBits(pBitmap,0,0,W,H,Stride,Scan,BitmapData)
		msgbox error lock
    Loop, %h% 
    {
    y := A_Index-1
        Loop, %w%
        {
            
            x := A_Index-1
            CurrentColor := Gdip_GetLockBitPixel(Scan,X,Y,Stride)
			If ( (CurrentColor != color_keep ))
                Gdip_SetLockBitPixel(color_replace,Scan,X,Y,Stride)
        }
        
    }
Gdip_UnlockBits(pBitmap,BitmapData)

return
}



Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], MrHue, Rohwedder, Rxbie, songdg and 375 guests