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  |
luoganda
Messages: 214 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   |
 |
koldo
Messages: 3435 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
|
|
|
|
|
|
Goto Forum:
Current Time: Tue May 13 23:29:34 CEST 2025
Total time taken to generate the page: 0.03065 seconds
|