Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Fastest way to capture control as image
Fastest way to capture control as image [message #60600] Thu, 30 May 2024 15:15 Go to next message
luoganda is currently offline  luoganda
Messages: 205
Registered: November 2016
Experienced Member
What would be the best way to capture GLCtrl(or even screen) pixels into ImageBuffer?
There is a demo GrabDesktop(or something like that), but it's just for win32(gdi) and it's too slow,
i think it's using SysInfo as main capturer(Snap_DesktopRectangle,etc).

I tried using glReadPixels(0,0,xs,ys,GL_BGRA_EXT,GL_UNSIGNED_BYTE,~ib);
but i always get an error 1282. Also tried GL_BGRA and GL_RGBA, the same thing.

This would be probably the best way, or is there a better one,
eg upp-ish one?

[Updated on: Thu, 30 May 2024 15:17]

Report message to a moderator

Re: Fastest way to capture control as image [message #60601 is a reply to message #60600] Fri, 31 May 2024 08:21 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3378
Registered: August 2008
Senior Veteran
Hi Luoganda

There is this in GLCanvas. It works if the control is selected.

Image GLCanvas::GetImage() {
	Size sz = GetSize();
	ImageBuffer ib(sz);

	glGetError();
	glReadPixels(0, 0, sz.cx, sz.cy, GL_BGRA_EXT, GL_UNSIGNED_BYTE, static_cast<GLvoid *>(~ib));
	if (GL_NO_ERROR != glGetError())
		return Null;
	
	Buffer<RGBA> temp(sz.cx);
	for(int i = 0; i < sz.cy/2; i++){
		memcpy(temp,ib[i], sz.cx*sizeof(RGBA));
		memcpy(ib[i], ib[sz.cy-1-i], sz.cx*sizeof(RGBA));
		memcpy(ib[sz.cy-1-i], temp, sz.cx*sizeof(RGBA));
	}
	
	for (int y = 0; y < sz.cy; y++)
		for (int x = 0; x < sz.cx; x++) 
			ib[y][x].a = 255;

	return ib;
}


Best regards
Iñaki
Re: Fastest way to capture control as image [message #60603 is a reply to message #60600] Fri, 31 May 2024 18:25 Go to previous messageGo to next message
luoganda is currently offline  luoganda
Messages: 205
Registered: November 2016
Experienced Member
koldo, this probably works.

For GLCtrl, it seems glReadPixels must be called within GLPaint,
since at that time - gl stuff is probably set up rightly to call that func.
Previously i tried to call it within LeftUp and it of course did not work as expected.
This is probably the reason why control(as you proposed) must be selected - to work.

Anyway, but what about independently capturing whole screen
or specific part of the screen(something like ffmpeg), is this possible without using too much low level gl code in Upp?
Some kind of trick would be creating invisible child of TopWindow, eg childTopWindowCtrl and capturing from that,
altough it would be a workaround.
I don't know if this would work, altough if there is a better way - it would be prefered.
Re: Fastest way to capture control as image [message #60604 is a reply to message #60603] Fri, 31 May 2024 21:02 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3378
Registered: August 2008
Senior Veteran
Hi Luoganda

In Anboto/SysInfo/ScreenGrab.cpp you can find functions to take images directly from the screen.


Best regards
Iñaki
Re: Fastest way to capture control as image [message #60606 is a reply to message #60600] Sat, 01 June 2024 17:27 Go to previous message
luoganda is currently offline  luoganda
Messages: 205
Registered: November 2016
Experienced Member
yes, that was the 1st i checked out,
but it's too slow for eg half(or fullScreen) capture - since regular gdi funcs are used.

Anyway, thanks for the reply, maybe i'll make something out from gl code.

[Updated on: Sat, 01 June 2024 17:44]

Report message to a moderator

Previous Topic: Horizontal Mouse Wheel support request
Next Topic: selection in ColumnList
Goto Forum:
  


Current Time: Sat Jul 27 12:27:11 CEST 2024

Total time taken to generate the page: 0.02006 seconds