zhda

zhda

0个粉丝

7

问答

0

专栏

0

资料

zhda  发布于  2012-12-04 11:37:28
采纳率 0%
7个问答
2803

Windows Mobile 相机操作

 

本文讲述了如何在Windows Mobile下启动相机的功能

当前测试环境:

IDE: VS2008

SDK: Windows Mobile 5.0

参考:

《在Windows Mobile上使用GDI+》《Windows Mobile图像系统开发》《Windows Mobile三维编程》

例子:

请下载本文附带例子工程

技术实现:

要实现启动Windows Mobile相机功能,主要使用到一个API: SHCameraCapture(),该函数主要启动一个相机拍摄的对话框,用来拍摄相片和视频。

函数原型:

HRESULT SHCameraCapture (

PSHCAMERACAPTURE pshcc

);

参数:

pshcc

[in/out] 参考SHCAMERACAPTURE 结构体, 它包含了初始化 SHCameraCapture 函数的信息, 并且包含完全合法的相片或视频的路径名的参考信息。

返回值:

S_OK

执行成功。

S_FALSE

用户终止相机拍摄的对话框。

E_OUTOFMEMORY

没有足够的内存存储图片或视频。

E_INVALIDARG

一个不合法的冲突。

"HRESULT_FROM_WIN32 (ERROR_RESOURCE_DISABLED)"

该错误表明相机无法使用是由于某个特定的条件值引起。

参考代码:

VOID StartCamera(HWND hwndDlg)

{

 HRESULT         hr;

 HRESULT         hReturn;

 SHCAMERACAPTURE shcc;

 LONG            lCheckStateInitialDir;

 LONG            lCheckStateDefaultFileName;

 LONG            lCheckStateTitle;

 LONG            lCheckStateResolution;

 LONG            lCheckStateVideoTimeLimit;

 TCHAR           szInitialDir[MAX_INITIAL_DIR] = { 0 };

 TCHAR           szDefaultFileName[MAX_FILE_NAME] = { 0 };

 TCHAR           szTitle[MAX_TITLE] = { 0 };

 DWORD           dwResolutionWidth;

 DWORD           dwResolutionHeight;

 DWORD           dwVideoTimeLimit;

 LPCTSTR         szFormat;

 TCHAR           szMessage[MAX_MESSAGE] = { 0 };

 // Get the state of the checkboxs

 lCheckStateInitialDir = SendDlgItemMessage(hwndDlg, IDC_CHECK_INITIAL_DIR, BM_GETCHECK, 0, 0);

 lCheckStateDefaultFileName = SendDlgItemMessage(hwndDlg, IDC_CHECK_DEFAULT_FILE_NAME, BM_GETCHECK, 0, 0);

 lCheckStateTitle = SendDlgItemMessage(hwndDlg, IDC_CHECK_TITLE, BM_GETCHECK, 0, 0);

 lCheckStateResolution = SendDlgItemMessage(hwndDlg, IDC_CHECK_RESOLUTION, BM_GETCHECK, 0, 0);

 lCheckStateVideoTimeLimit = SendDlgItemMessage(hwndDlg, IDC_CHECK_VIDEO_TIME_LIMIT, BM_GETCHECK, 0, 0);

 // Get the user inputs of the edit controls

 GetDlgItemText(hwndDlg, IDC_INITIAL_DIR, szInitialDir, ARRAYSIZE(szInitialDir));

 GetDlgItemText(hwndDlg, IDC_DEFAULT_FILE_NAME, szDefaultFileName, ARRAYSIZE(szDefaultFileName));

 GetDlgItemText(hwndDlg, IDC_TITLE, szTitle, ARRAYSIZE(szTitle));

 dwResolutionWidth = GetDlgItemInt(hwndDlg, IDC_RESOLUTION_WIDTH, NULL, FALSE);

 dwResolutionHeight = GetDlgItemInt(hwndDlg, IDC_RESOLUTION_HEIGHT, NULL, FALSE);

 dwVideoTimeLimit = GetDlgItemInt(hwndDlg, IDC_VIDEO_TIME_LIMIT, NULL, FALSE);

 // Specify the arguments of SHCAMERACAPTURE

 ZeroMemory(&shcc, sizeof(shcc));

 shcc.cbSize             = sizeof(shcc);

 shcc.hwndOwner          = hwndDlg;

 shcc.pszInitialDir      = (BST_UNCHECKED == lCheckStateInitialDir) ? CECAMERA_DEFAULT_INITIAL_DIR : szInitialDir;

 shcc.pszDefaultFileName = (BST_UNCHECKED == lCheckStateDefaultFileName) ? CECAMERA_DEFAULT_FILE_NAME : szDefaultFileName;

 shcc.pszTitle           = (BST_UNCHECKED == lCheckStateTitle) ? CECAMERA_DEFAULT_TITLE : szTitle;

 shcc.StillQuality       = g_StillQuality;

 shcc.VideoTypes         = g_VideoTypes;

 shcc.nResolutionWidth   = (BST_UNCHECKED == lCheckStateResolution) ? CECAMERA_DEFAULT_RESOLUTION_WIDTH : dwResolutionWidth;

 shcc.nResolutionHeight  = (BST_UNCHECKED == lCheckStateResolution) ? CECAMERA_DEFAULT_RESOLUTION_HEIGHT : dwResolutionHeight;

 shcc.nVideoTimeLimit    = (BST_UNCHECKED == lCheckStateVideoTimeLimit) ? CECAMERA_DEFAULT_VIDEO_TIME_LIMIT : dwVideoTimeLimit;

 shcc.Mode               = g_Mode;

 // Call SHCameraCapture() function

 g_bCameraRunning = TRUE;

 hReturn = SHCameraCapture(&shcc);

 g_bCameraRunning = FALSE;

 // Check the return codes of the SHCameraCapture() function

 switch (hReturn)

 {

 case S_OK:

     // The method completed successfully.

     szFormat = (LPCTSTR)LoadString(g_hInstance, IDS_NOERROR, NULL, 0);

     CPR(szFormat);

     CHR(StringCchPrintf(szMessage, ARRAYSIZE(szMessage), szFormat, shcc.szFile));

     MessageBox(hwndDlg, szMessage, g_szCaption, MB_OK | MB_ICONINFORMATION);

     break;

 case S_FALSE:

  &am, p;nb, sp;  // The user canceled the Camera Capture dialog box.

     break;

 case E_INVALIDARG:

     // An invalid argument was specified.

     szFormat = (LPCTSTR)LoadString(g_hInstance, IDS_ERROR_INVALIDARG, NULL, 0);

     CPR(szFormat);

     MessageBox(hwndDlg, szFormat, g_szCaption, MB_OK | MB_ICONEXCLAMATION);

     break;

 case E_OUTOFMEMORY:

     // There is not enough memory to save the image or video.

     szFormat = (LPCTSTR)LoadString(g_hInstance, IDS_ERROR_OUTOFMEMORY, NULL, 0);

     CPR(szFormat);

     MessageBox(hwndDlg, szFormat, g_szCaption, MB_OK | MB_ICONSTOP);

     break;

 case HRESULT_FROM_WIN32(ERROR_RESOURCE_DISABLED):

     // The camera is disabled.

     szFormat = (LPCTSTR)LoadString(g_hInstance, IDS_ERROR_CAMERADISABLED, NULL, 0);

     CPR(szFormat);

     MessageBox(hwndDlg, szFormat, g_szCaption, MB_OK | MB_ICONSTOP);

     break;

 default:

     // An unknown error occurred.

     szFormat = (LPCTSTR)LoadString(g_hInstance, IDS_ERROR_UNKNOWN, NULL, 0);

     CPR(szFormat);

     CHR(StringCchPrintf(szMessage, ARRAYSIZE(szMessage), szFormat, hReturn));

     MessageBox(hwndDlg, szMessage, g_szCaption, MB_OK | MB_ICONSTOP);

     break;

 }

Error:

 return;

}

出自:http://www.a3gs.com/BookViews.asp?InfoID=2940&classID=925&InfoType=0]

我来回答
回答0个
时间排序
认可量排序
易百纳技术社区暂无数据
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
+ 添加网盘链接/附件

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

易百纳技术社区