是否可以在BB10(本机)中以编程方式截取DockLayout及其所有子容器的屏幕截图?我在文档中找到了Screenshot类,但它只能采用显示或应用程序窗口截图...
任何提示或提示?
感谢。
答案 0 :(得分:0)
这是我用于在程序控制下捕获屏幕区域的基本代码。
请注意,您只能捕获此代码所在程序显示的屏幕。
void ScreenCapture::capture(qreal x, qreal y, qreal width, qreal height)
{
smDebug(1) << "Capturing" << x << y << width << height;
screen_pixmap_t screen_pix;
screen_buffer_t screenshot_buf;
screen_context_t context;
char *screenshot_ptr = NULL;
int screenshot_stride = 0;
int usage, format;
int size[2];
screen_create_context(&context, 0);
screen_create_pixmap(&screen_pix, context);
usage = SCREEN_USAGE_READ | SCREEN_USAGE_NATIVE;
screen_set_pixmap_property_iv(screen_pix, SCREEN_PROPERTY_USAGE, &usage);
format = SCREEN_FORMAT_RGBA8888;
screen_set_pixmap_property_iv(screen_pix, SCREEN_PROPERTY_FORMAT, &format);
size[0] = 0;
size[1] = 0;
screen_get_window_property_iv(Application::instance()->mainWindow()->handle(), SCREEN_PROPERTY_SIZE, size);
smDebug(1) << size[0] << 'x' << size[1];
screen_set_pixmap_property_iv(screen_pix, SCREEN_PROPERTY_BUFFER_SIZE, size);
screen_create_pixmap_buffer(screen_pix);
screen_get_pixmap_property_pv(screen_pix, SCREEN_PROPERTY_RENDER_BUFFERS,
(void**)&screenshot_buf);
screen_get_buffer_property_pv(screenshot_buf, SCREEN_PROPERTY_POINTER,
(void**)&screenshot_ptr);
screen_get_buffer_property_iv(screenshot_buf, SCREEN_PROPERTY_STRIDE,
&screenshot_stride);
screen_read_window(Application::instance()->mainWindow()->handle(), screenshot_buf, 0, NULL ,0);
QByteArray array;
int nbytes = size[0] * size[1] * 4;
write_bitmap_header(nbytes, array, size);
for (int i = 0; i < size[1]; i++)
{
array.append(screenshot_ptr + i * screenshot_stride, size[0] * 4);
}
QImage image = QImage::fromData(array, "BMP");
image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
baseImage = QImage(width,height,QImage::Format_ARGB32_Premultiplied);
baseImage.painter().drawImage(0, 0, image, x, y, width, height);
if (mWaterMarkImage != NULL)
baseImage.updateToView(mWaterMarkImage);
soundplayer_play_sound("event_camera_shutter");
screen_destroy_pixmap(screen_pix);
smDebug(1) << "capture done.";
}