Dark Band Around GDI+ Screenshot

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kkleinfelter
Posts: 32
Joined: 21 Dec 2018, 10:59

Dark Band Around GDI+ Screenshot

17 Sep 2019, 11:50

When I take a screenshot of a File Explorer window using GDI+, the title bar come out with a black background, although the icons are rendered properly. My real File Explorer window has white background.

The status bar and the scroll bar also come out black. Attached image shows the title bar. The background should be white!

The code I'm using looks like:

Code: Select all

 pBitmap := Gdip_BitmapFromHWND(hwnd,0)
 bufLen := GdiPlus_SaveImageToBuffer( pBitmap, Buffer, "PNG" )
 tmp := BinWrite("C:\temp\plain-image.png", Buffer)
 Gdip_DisposeImage(pBitmap)
 VarSetCapacity(Buffer, 0)
How do I get title/scroll/status captured with their true colors?
stripe.png
stripe.png (11.13 KiB) Viewed 593 times
iPhilip
Posts: 835
Joined: 02 Oct 2013, 12:21

Re: Dark Band Around GDI+ Screenshot

17 Sep 2019, 12:58

Hi @kkleinfelter,

You might be interested in this post where we discussed the same issue.

- iPhilip
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Dark Band Around GDI+ Screenshot

17 Sep 2019, 13:27

Code: Select all

fromHwnd(hwnd, wOffset := 0, hOffset := 0, xOffset := 0, yOffset := 0) {
	WinGetPos x, y, w, h, % "ahk_id" hwnd

	hbm1 := CreateDIBSection(w, h)
	hdc1 := CreateCompatibleDC()
	obm1 := SelectObject(hdc1, hbm1)
	DllCall("PrintWindow", "Ptr", hwnd, "Ptr", hdc1, "UInt", 2)

	w -= wOffset
	h -= hOffset
	hbm2 := CreateDIBSection(w, h)
	hdc2 := CreateCompatibleDC()
	obm2 := SelectObject(hdc2, hbm2)
	BitBlt(hdc2, 0, 0, w, h, hdc1, xOffset, yOffset)

	pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm2)

	SelectObject(hdc1, obm1)
	SelectObject(hdc2, obm2)
	DeleteObject(hbm1)
	DeleteObject(hbm2)
	DeleteDC(hdc1)
	DeleteDC(hdc2)

	return pBitmap
}
but ull have to readjust the offsets(probably on a per app basis) to get rid of the black bars
Spoiler

Code: Select all

#Include <Gdip_All>

hwnd := WinExist("some folder")
fromHwnd(hwnd)
fromHwnd(hwnd, 16, 9, 8, 1)

Esc::ExitApp

fromHwnd(hwnd, wOffset := 0, hOffset := 0, xOffset := 0, yOffset := 0) {
	WinGetPos x, y, w, h, % "ahk_id" hwnd

	hbm1 := CreateDIBSection(w, h)
	hdc1 := CreateCompatibleDC()
	obm1 := SelectObject(hdc1, hbm1)
	DllCall("PrintWindow", "Ptr", hwnd, "Ptr", hdc1, "UInt", 2)

	w -= wOffset
	h -= hOffset
	hbm2 := CreateDIBSection(w, h)
	hdc2 := CreateCompatibleDC()
	obm2 := SelectObject(hdc2, hbm2)
	BitBlt(hdc2, 0, 0, w, h, hdc1, xOffset, yOffset)

	Gui New
	Gui Add, Picture, w%w% h%h%, HBITMAP: %hbm2%
	Gui Show
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Draken, oktavimark and 317 guests