Capturing Image via CaptureToBuffer not works on Android
-
Hi,
I just tried to capture an image from the camera directly from the buffer. No matter what I try nothing works unfortunatley.1.) Via QCameraImageCapture:
void Qml::iniObjects() { m_pRootObj = m_pEngine->rootObjects().first(); QObject *qmlCamera = m_pRootObj->findChild<QObject*>("oCamera"); m_pCamera = qvariant_cast<QCamera *>(qmlCamera->property("mediaObject")); m_pCamera->setCaptureMode(QCamera::CaptureStillImage); m_pImgCapt = new QCameraImageCapture(m_pCamera); m_pImgCapt->setCaptureDestination(QCameraImageCapture::CaptureToBuffer); connect(m_pImgCapt,SIGNAL(imageAvailable(int,const QVideoFrame&)), this, SLOT(updImageAvailable(int,const QVideoFrame&))); bool dest = m_pImgCapt->isCaptureDestinationSupported(QCameraImageCapture::CaptureToBuffer); qDebug() << dest; **-> true** QList<QVideoFrame::PixelFormat> format = m_pImgCapt->supportedBufferFormats(); qDebug() << format; **-> (Format_Jpeg)** } void Qml::updImageAvailable(int id, const QVideoFrame &buffer) { qDebug() << "Image"; }
Result: No error, no signal
2.) Via QMediaService: Same code as before, excepted the following.
QMediaService *service = m_pCamera->service(); QMediaControl *control = service->requestControl(QCameraImageCaptureControl_iid); QCameraImageCaptureControl *captureControl = qobject_cast<QCameraImageCaptureControl*>(control); connect(captureControl,SIGNAL(imageAvailable(int,const QVideoFrame&)), this, SLOT(updImageAvailable(int,const QVideoFra@me&)));
Result: No error, no signal
Anyone an idea?
Thanks in advance...
-
connect(captureControl,SIGNAL(imageAvailable(int,const QVideoFrame&)), this, SLOT(updImageAvailable(int,const QVideoFra@me&)));
has a @ in it...could you use the new connect syntax:
connect(m_pImgCapt,&QCameraImageCapture::imageAvailable, this, &Qml::updImageAvailable);
andconnect(captureControl,&QCameraImageCaptureControl::imageAvailable, this, &Qml::updImageAvailable);
P.S.
did you name your class Qml? I see a huge potential for naming clashes... -
@p3c0 and @VRonin : Thxs for your fast response!
I checked all your proposals but no difference. Regarding @ this was a inexplicable copy paste failure. But fortunately I found the reason. Maybe others are interessted:As I read the official docu for "QCameraImageCapture::capture" I found no hint regarding the signal "QCameraImageCapture::imageAvailable()". So I thought falsely that this signal is automatically created everytime a QVideoFrame is ready. But obviously also this signal is created only after calling "QCameraImageCapture::capture()". As my understanding this case is not considered in the docu.
This also means if you set QCameraImageCapture::setCaptureDestination(QCameraImageCapture::CaptureToBuffer) there is no picture saved properly, independed if the passed QString to "::capture(""filename") is empty or not. -
@PowerNow Hello r u using QML? I capture images using QCamera. Check this thread from yesterday :)
https://forum.qt.io/topic/71920/qimage-manipulation-crashes-on-android