视频编程
(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.morning-sea.com.cn
曙海教育
曙海嵌入式
(MTK培训,Android培训,FPGA培训,DSP培训,iPhone培训)
上海总部电话:021-51875830 深圳:4008699035 北京:010-51292078
网址:http://www.51qianru.cn
版权所有-曙海教育 转发请注明出处
|