Yao Chunli
2022-06-21 e00d5a1575d26f8fec1be6fa8a844203cd66a24c
提交 | 用户 | age
4b03ae 1 #include "StdAfx.h"
Q 2 #include "MyCameraBase.h"
3
4 MyCamera::MyCamera(void)
5 {
6     m_nWaitTime=500;
7     ResultStr.Format(_T("Camera Not Defined!"));
8 }
9
10
11 MyCamera::~MyCamera(void)
12 {
13 }
14
15 MySimCamera::MySimCamera(void)
16 {
17 }
18
19 MySimCamera::~MySimCamera(void)
20 {
21
22 }
23 MySimCamera::MySimCamera(CString sFilePathName)
24 {
25     SetSim(sFilePathName,0,0);
26 }
27 int MySimCamera::GetNextFilePathName()
28 {
29     if (nTotalImageFileCount<=0) return -1;
30     if (nCurImageFileIndex>=nTotalImageFileCount)
31     {
32         nCurImageFileIndex=0;
33     }
34     CFileFind FileFinder;
35     int k=FileFinder.FindFile(ImageFilePathName);
36     for (int i=0;i<=nCurImageFileIndex&&k;i++)
37     {
38         int k=FileFinder.FindNextFileW();
39         int j=FileFinder.IsDirectory();
40         int l=FileFinder.IsDots();
41         if (j&&l) {continue;}            //既是目录,又是点。那么就是 .或.. 跳过
42         if (j) {continue;}
43     }
44     CurFilePathName=FileFinder.GetFilePath();
45     nCurImageFileIndex++;
46     return 1;
47 }
48 int MySimCamera::SetSim(CString sFilePathName, int pixeltype, int w, int h)
49 {
50     ImageFilePathName=sFilePathName;
51     CFileFind FileFinder;
52     int i=FileFinder.FindFile(ImageFilePathName);
53     nTotalImageFileCount=0;
54     nCurImageFileIndex=0;
55
56     while (i)
57     {
58         i=FileFinder.FindNextFileW();
59         int j=FileFinder.IsDirectory();
60         int k=FileFinder.IsDots();
61         if (j&&k) {continue;}            //既是目录,又是点。那么就是 .或.. 跳过
62         if (j) {continue;}
63         nTotalImageFileCount++;
64         if (nTotalImageFileCount==1) //读取到的第一个文件
65         {
66             CurFilePathName=FileFinder.GetFilePath();
67             Gdiplus::Bitmap bitmap1(CurFilePathName);
68             w=bitmap1.GetWidth();
69             h=bitmap1.GetHeight();
70             m_nWidth=w;
71             m_nHeight=h;
72             m_PixelFormat=pixeltype;
73         }
74     }
75     if (nTotalImageFileCount>0) {return nTotalImageFileCount;}
76     else {return 0;}
77 }
78 int MySimCamera::OpenCamera(int)
79 {
80     m_IsCameraOpened=1;
81     ResultStr.Format(_T("Sim相机%s打开成功"),ImageFilePathName);
82     return CameraOk;
83 }
84 int MySimCamera::CloseCamera()
85 {
86     m_IsCameraOpened=0;
87     return CameraOk;
88 }
89 int MySimCamera::SetExposureTime(double ExposeTime1)
90 {
91     return CameraOk;
92 }
93 int MySimCamera::StartGrab()
94 {
95     if (GetNextFilePathName()!=1) return CameraError;        //先获取文件列表中的文件名
96     ResultStr.Format(_T("File %s "),CurFilePathName);
97     Gdiplus::Bitmap bitmap1(CurFilePathName);        //读取文件
98     int w,h;
99     Gdiplus::BitmapData bitmapData1;
100     w=bitmap1.GetWidth();
101     h=bitmap1.GetHeight();
102     Gdiplus::Rect rect1(0,0,w,h);
103     Gdiplus::PixelFormat pixelformat1=bitmap1.GetPixelFormat();
104     //转换格式.
105     if (pixelformat1==PixelFormat8bppIndexed)
106     {    //认为是Raw格式
107         bitmapData1.Width=w;
108         bitmapData1.Height=h;
109         bitmap1.LockBits(&rect1,Gdiplus::ImageLockModeRead,PixelFormat8bppIndexed,&bitmapData1);
110         Image1.CopyFromBuf(bitmapData1.Scan0,w,h,bitmapData1.Stride,m_PixelFormat);
111         bitmap1.UnlockBits(&bitmapData1);
112
113         return GrabOK;
114     }else if (pixelformat1==PixelFormat24bppRGB)
115     {
116         return -1;
117     }else if (pixelformat1==PixelFormat32bppRGB)
118     {
119         return -1;
120     }
121     return CameraOk;
122 }
123 int MySimCamera::StopGrab()
124 {
125     return CameraOk;
126 }
127 int MySimCamera::WaitForGrabFinish(int nTimeWait)
128 {
129     return CameraOk;
130 }
131 int MySimCamera::FetchImageData()
132 {
133     return CameraOk;
134 }