#include "StdAfx.h"
|
#include "MyCameraBase.h"
|
|
MyCamera::MyCamera(void)
|
{
|
m_nWaitTime=500;
|
ResultStr.Format(_T("Camera Not Defined!"));
|
}
|
|
|
MyCamera::~MyCamera(void)
|
{
|
}
|
|
MySimCamera::MySimCamera(void)
|
{
|
}
|
|
MySimCamera::~MySimCamera(void)
|
{
|
|
}
|
MySimCamera::MySimCamera(CString sFilePathName)
|
{
|
SetSim(sFilePathName,0,0);
|
}
|
int MySimCamera::GetNextFilePathName()
|
{
|
if (nTotalImageFileCount<=0) return -1;
|
if (nCurImageFileIndex>=nTotalImageFileCount)
|
{
|
nCurImageFileIndex=0;
|
}
|
CFileFind FileFinder;
|
int k=FileFinder.FindFile(ImageFilePathName);
|
for (int i=0;i<=nCurImageFileIndex&&k;i++)
|
{
|
int k=FileFinder.FindNextFileW();
|
int j=FileFinder.IsDirectory();
|
int l=FileFinder.IsDots();
|
if (j&&l) {continue;} //¼ÈÊÇĿ¼£¬ÓÖÊǵ㡣ÄÇô¾ÍÊÇ .»ò.. Ìø¹ý
|
if (j) {continue;}
|
}
|
CurFilePathName=FileFinder.GetFilePath();
|
nCurImageFileIndex++;
|
return 1;
|
}
|
int MySimCamera::SetSim(CString sFilePathName, int pixeltype, int w, int h)
|
{
|
ImageFilePathName=sFilePathName;
|
CFileFind FileFinder;
|
int i=FileFinder.FindFile(ImageFilePathName);
|
nTotalImageFileCount=0;
|
nCurImageFileIndex=0;
|
|
while (i)
|
{
|
i=FileFinder.FindNextFileW();
|
int j=FileFinder.IsDirectory();
|
int k=FileFinder.IsDots();
|
if (j&&k) {continue;} //¼ÈÊÇĿ¼£¬ÓÖÊǵ㡣ÄÇô¾ÍÊÇ .»ò.. Ìø¹ý
|
if (j) {continue;}
|
nTotalImageFileCount++;
|
if (nTotalImageFileCount==1) //¶ÁÈ¡µ½µÄµÚÒ»¸öÎļþ
|
{
|
CurFilePathName=FileFinder.GetFilePath();
|
Gdiplus::Bitmap bitmap1(CurFilePathName);
|
w=bitmap1.GetWidth();
|
h=bitmap1.GetHeight();
|
m_nWidth=w;
|
m_nHeight=h;
|
m_PixelFormat=pixeltype;
|
}
|
}
|
if (nTotalImageFileCount>0) {return nTotalImageFileCount;}
|
else {return 0;}
|
}
|
int MySimCamera::OpenCamera(int)
|
{
|
m_IsCameraOpened=1;
|
ResultStr.Format(_T("SimÏà»ú%s´ò¿ª³É¹¦"),ImageFilePathName);
|
return CameraOk;
|
}
|
int MySimCamera::CloseCamera()
|
{
|
m_IsCameraOpened=0;
|
return CameraOk;
|
}
|
int MySimCamera::SetExposureTime(double ExposeTime1)
|
{
|
return CameraOk;
|
}
|
int MySimCamera::StartGrab()
|
{
|
if (GetNextFilePathName()!=1) return CameraError; //ÏÈ»ñÈ¡ÎļþÁбíÖеÄÎļþÃû
|
ResultStr.Format(_T("File %s "),CurFilePathName);
|
Gdiplus::Bitmap bitmap1(CurFilePathName); //¶ÁÈ¡Îļþ
|
int w,h;
|
Gdiplus::BitmapData bitmapData1;
|
w=bitmap1.GetWidth();
|
h=bitmap1.GetHeight();
|
Gdiplus::Rect rect1(0,0,w,h);
|
Gdiplus::PixelFormat pixelformat1=bitmap1.GetPixelFormat();
|
//ת»»¸ñʽ.
|
if (pixelformat1==PixelFormat8bppIndexed)
|
{ //ÈÏΪÊÇRaw¸ñʽ
|
bitmapData1.Width=w;
|
bitmapData1.Height=h;
|
bitmap1.LockBits(&rect1,Gdiplus::ImageLockModeRead,PixelFormat8bppIndexed,&bitmapData1);
|
Image1.CopyFromBuf(bitmapData1.Scan0,w,h,bitmapData1.Stride,m_PixelFormat);
|
bitmap1.UnlockBits(&bitmapData1);
|
|
return GrabOK;
|
}else if (pixelformat1==PixelFormat24bppRGB)
|
{
|
return -1;
|
}else if (pixelformat1==PixelFormat32bppRGB)
|
{
|
return -1;
|
}
|
return CameraOk;
|
}
|
int MySimCamera::StopGrab()
|
{
|
return CameraOk;
|
}
|
int MySimCamera::WaitForGrabFinish(int nTimeWait)
|
{
|
return CameraOk;
|
}
|
int MySimCamera::FetchImageData()
|
{
|
return CameraOk;
|
}
|