/*! Starts the camera with the given device. The available devices can be queried with the availableDevices method. Starting will release and destroy all earlier camera resources before creating new ones. */ void CustomCamera::start(const QString &device) { destroyResources(); m_camera = new QCamera(device.toLatin1(), this); m_videoSurface = new VideoSurface(this, m_camera); m_camera->setViewfinder(m_videoSurface); // Set the image capturing objects. m_cameraImageCapture = new QCameraImageCapture(m_camera); m_cameraImageCapture->setCaptureDestination( QCameraImageCapture::CaptureToFile); // The following code finds a 16:9 resolution and sets it as capture // resolution. The view finder image should also change to corresponding // aspect ratio. // Find resolution that matches to device's full screen, 16:9 QImageEncoderSettings imageSettings; imageSettings.setCodec("image/jpeg"); QList<QSize> resolutions = m_cameraImageCapture->supportedResolutions(); QSize resolution; foreach (const QSize size, resolutions) { float a = size.width() * 1.0f / (size.height() * 1.0f); float b = 640.0f / 360.0f; if (qAbs(a - b) <= 0.1f * qMin(qAbs(a), qAbs(b))) { resolution = size; break; } }
QImageEncoderSettings S60ImageEncoderControl::imageSettings() const { // Update setting values from session QImageEncoderSettings settings; settings.setCodec(m_session->settings()->imageCodec()); settings.setResolution(m_session->settings()->imageResolution()); settings.setQuality(m_session->settings()->imageQuality()); return settings; }
QImageEncoderSettings AndroidCamImageEncoderControl::imageSettings() const { QImageEncoderSettings imageEncoderSettings; if(!m_imageSettings.isEmpty()) { switch(m_imageSettings.at(0)) { case 256: imageEncoderSettings.setCodec(QLatin1String("JPEG")); break; case 17: imageEncoderSettings.setCodec(QLatin1String("NV21")); break; case 4: imageEncoderSettings.setCodec(QLatin1String("RGB_565")); break; case 20: imageEncoderSettings.setCodec(QLatin1String("YUY2")); break; default: imageEncoderSettings.setCodec(QLatin1String("JPEG")); break; } imageEncoderSettings.setResolution(QSize(m_imageSettings.at(1),m_imageSettings.at(2))); } else { imageEncoderSettings.setCodec(QLatin1String("JPEG")); imageEncoderSettings.setResolution(QSize(QtCameraJni::getSupportedImageResolutions().at(0),QtCameraJni::getSupportedImageResolutions().at(1))); } return imageEncoderSettings; }
void FSWebCam::setCamera(const QByteArray &cameraDevice) { delete camera; delete imageCapture; if (cameraDevice.isEmpty()){ camera = new QCamera; }else{ camera = new QCamera(cameraDevice); } imageCapture = new QCameraImageCapture(camera); QImageEncoderSettings imageSettings = imageCapture->encodingSettings(); qDebug() << imageCapture->supportedResolutions(); qDebug() << imageSettings.resolution(); //QImageEncoderSettings imageSettings; #ifdef LINUX #else imageSettings.setCodec("image/jpeg"); imageSettings.setResolution(1280, 960); #endif imageCapture->setEncodingSettings(imageSettings); camera->setViewfinder(FSController::getInstance()->controlPanel->ui->viewfinder ); FSController::getInstance()->controlPanel->ui->cameraLabel->setStyleSheet("border-style: solid; border-color: black; border-width: 3px 1px 3px 1px;"); FSController::getInstance()->controlPanel->ui->cameraLabel->setText(""); camera->setCaptureMode(QCamera::CaptureStillImage); //connect(imageCapture, SIGNAL(readyForCaptureChanged(bool)), this, SLOT(readyForCapture(bool))); connect(imageCapture, SIGNAL(imageCaptured(int,QImage)), this, SLOT(processCapturedImage(int,QImage))); connect(imageCapture, SIGNAL(imageSaved(int,QString)), this, SLOT(imageSaved(int,QString))); camera->start(); QStringList res = imageCapture->supportedImageCodecs(); //QList<QSize> res = imageCapture->supportedResolutions(); //QSize r; QString r; foreach(r,res){ qDebug() << "Supported Resolutions:"<<r; } qDebug() << "set camera:" << cameraDevice; }
void MiCamara::on_capture_triggered() { imgcap->setCaptureDestination(QCameraImageCapture::CaptureToFile); QImageEncoderSettings imageSettings; imageSettings.setCodec("image/jpeg"); imageSettings.setResolution(1600, 1200); imgcap->setEncodingSettings(imageSettings); cam->setCaptureMode(QCamera::CaptureStillImage); cam->start(); cam->searchAndLock(); QString location; QFileDialog fldao(this); fldao.setWindowTitle("Guardar captura"); fldao.setAcceptMode(QFileDialog::AcceptSave); fldao.setFileMode(QFileDialog::AnyFile); fldao.setNameFilter("JPEG (*.jpeg)"); fldao.setNameFilterDetailsVisible(true); if (fldao.exec() == QDialog::Rejected) { cam->unlock(); return; } location = fldao.selectedFiles().first(); imgcap->capture(location); cam->unlock(); }