視頻編程
(2)創建類
iCamera = CCamera::NewL(*this,0);
(3)保留攝像頭
iCamera->Reserve();
2.調用observer,ReserveComplete()方法
void CImageCapturerEngine::ReserveComplete(TInt aError)
{
if(aError == KErrNone)
{
iCamera->PowerOn();
}
else
{
iObserver.OnError(aError);
}
}
注意其中的PowerOn()給相機上電
3.調用Observer的PowerOnComplete()函數通知系統上電完成
void CImageCapturerEngine::PowerOnComplete(TInt aError)
{
TInt err = aError;
if(aError == KErrNone)
{
TCameraInfo info;
iCamera->CameraInfo(info);
if ((info.iOptionsSupported&TCameraInfo::EContrastSupported)!=0)
{
TRAP(err, iCamera->SetContrastL(CCamera::EContrastAuto));
}
TRAP(err,StartViewFinderL());
if(err==KErrNone)
{
TRAP(err,PrepareImageCaptureL(KDefaultImageFormat));
}
}
if(err!=KErrNone)
{
iObserver.OnError(aError);
}
}
4.設置對比度,預覽圖像
void CImageCapturerEngine::ViewFinderFrameReady(CFbsBitmap&
aFrame)
{
iObserver.OnFrame(aFrame);
}
5.準備捕捉圖像
void CImageCapturerEngine::ImageReady(CFbsBitmap* aBitmap,HBufC8*
/*aData*/,TInt aError)
{
if(aError == KErrNone)
{
iObserver.OnImage(aBitmap);
}
else
{
iObserver.OnError(aError);
}
}
6.重要的函數:開始預覽圖像和停止預覽
void CImageCapturerEngine::StartViewFinderL()
{
TSize imageSize(KDefaultImageWidth,KDefaultImageHeight);
if(iCamera->ViewFinderActive())
{
// iObserver.OnError(KErrAlreadyActive)
}
else
{
iCamera->StartViewFinderBitmapsL(imageSize);
}
if(!iCamera->ViewFinderActive())
{
// iObserver.OnError(KErrNotActivated);
}
}
void CImageCapturerEngine::StopViewFinder()
{
iCamera->StopViewFinder();
}
7.捕捉圖像
void CImageCapturerEngine::CaptureImage()
{
iCamera->CaptureImage();
}
補充:
(1)iCamera->SetContrastL(CCamera::EContrastAuto));
EContrastAuto-自動設置
還可以設置-100到100之間的值
完整版本請見http://www.sw965.cn
曙海教育
曙海嵌入式
(MTK培訓,Android培訓,FPGA培訓,DSP培訓,iPhone培訓)
上?偛侩娫:021-51875830 深圳:4008699035 北京:010-51292078
網址:http://www.51qianru.cn
版權所有-曙海教育 轉發請注明出處
|