2015-05-06 31 views
-1

是否可以在BB10(本機)中以編程方式截取DockLayout等容器及其所有子項的屏幕截圖?我已經在文檔中找到了截圖類,但它只能顯示或應用程序窗口截圖...在BlackBerry10中以編程方式截圖查看/佈局

任何提示或提示?

謝謝。

+0

嘗試閱讀Qt文檔:http://doc.qt.io/qt-5/qwidget.html #grab –

+0

@SaZ Cascades使用QT 4.8 fyi –

回答

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."; 
    }