/*! 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; } }
void S60ImageEncoderControl::setImageSettings(const QImageEncoderSettings &settings) { if (!settings.isNull()) { // Notify that settings have been implicitly set and there's no need to // initialize them in case camera is changed m_session->settings()->notifySettingsSet(); if (!settings.codec().isEmpty()) m_session->settings()->setImageCodec(settings.codec()); // Set quality before resolution as quality defines the // resolution used in case it's not explicitly set m_session->settings()->setImageQuality(settings.quality()); m_session->settings()->setImageResolution(settings.resolution()); // Prepare ImageCapture with the settings and set error if needed int prepareSuccess = m_session->prepareImageCapture(); // Preparation fails with KErrNotReady if camera has not been started. // That can be ignored since settings are set internally in that case. if (prepareSuccess != KErrNotReady && prepareSuccess != KErrNone) m_session->setError(prepareSuccess, tr("Failed to apply image settings."), true); } else { m_session->setError(KErrNotSupported, tr("Unable to set undefined settings."), true); } }
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; }
QList<QSize> S60ImageEncoderControl::supportedResolutions( const QImageEncoderSettings &settings, bool *continuous) const { // Discrete resolutions are returned if (continuous) *continuous = false; return m_session->settings()->supportedImageResolutionsForCodec(settings.codec()); }
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 AndroidCamImageEncoderControl::setImageSettings(const QImageEncoderSettings &settings) { m_imageSettings.clear(); if(settings.codec() == QLatin1String("JPEG")) { m_imageSettings.append(256); } else if(settings.codec() == QLatin1String("NV21")) { m_imageSettings.append(17); } else if(settings.codec() == QLatin1String("RGB_565")) { m_imageSettings.append(4); } else if(settings.codec() == QLatin1String("YUY2")) { m_imageSettings.append(20); } else { m_imageSettings.append(256); } QSize resolution = settings.resolution(); if(!resolution.isEmpty()) { m_imageSettings.append(resolution.width()); m_imageSettings.append(resolution.height()); } else { m_imageSettings.append(QtCameraJni::getSupportedImageResolutions().at(0)); m_imageSettings.append(QtCameraJni::getSupportedImageResolutions().at(1)); } QtCameraJni::setImageSettings(m_imageSettings); }
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(); }