BOOL CNCaptureView::GetImageByRect(const CRect& rcSrc, CImage& Image) { if (m_pImage) { CImageDC dcImage(Image); DrawObjects(m_canvasImage.GetMemoryDC()); BitBlt(dcImage, 0, 0, rcSrc.Width(), rcSrc.Height(), m_canvasImage.GetMemoryDC(), rcSrc.left, rcSrc.top, SRCCOPY); CRect rcImage(0, 0, m_pImage->GetWidth(), m_pImage->GetHeight()); m_pImage->Draw(m_canvasImage, rcImage); return TRUE; } return FALSE; }
void MainWindow::shareDesktopUpdate() { // time the frame QTime frameTime; frameTime.start(); const int w = width_ * deviceScale_; const int h = height_ * deviceScale_; // take screenshot QPixmap desktopPixmap = QPixmap::grabWindow( QApplication::desktop()->winId(), x_, y_, w, h ); if( desktopPixmap.isNull( )) { handleStreamingError("Got NULL desktop pixmap"); return; } QImage image = desktopPixmap.toImage(); // render mouse cursor QPoint mousePos = ( QCursor::pos() - QPoint( x_, y_ )) * deviceScale_ - QPoint( cursor_.width()/2, cursor_.height()/2); QPainter painter( &image ); painter.drawImage( mousePos, cursor_ ); painter.end(); // Make sure to release the QImage before using it to update the segements // QImage Format_RGB32 (0xffRRGGBB) corresponds in fact to GL_BGRA == dc::BGRA dc::ImageWrapper dcImage((const void*)image.bits(), image.width(), image.height(), dc::BGRA); dcImage.compressionPolicy = dc::COMPRESSION_ON; bool success = dcStream_->send(dcImage) && dcStream_->finishFrame(); if( !success ) { handleStreamingError("Streaming failure, connection closed."); return; } regulateFrameRate(frameTime.elapsed()); }