首页 新闻 搜索 专区 学院

Windows Mobile调用拍照时设备假死现象。

0
悬赏园豆:40 [已关闭问题] 关闭于 2013-11-27 11:11

今天处理一个问题,程序在调用摄像头时有时候会出现屏幕和键盘失效的情况,只有开关能正常工作,我按下开关键后它会重复的调用摄像头这是什么原因???

 1             //GlobalCache.Instance.myWin32.DeHook();// 取消钩子
 2             //try
 3             //{
 4             //    CameraCaptureDialog cameraCapture = new CameraCaptureDialog();
 5             //    cameraCapture.Owner = this;
 6 
 7             //    // Specify the options as user specified.
 8             //    {
 9             //        cameraCapture.InitialDirectory = @"\My Documents";
10             //    }
11 
12             //    cameraCapture.DefaultFileName = null;
13             //    cameraCapture.Title = "YIDA_";
14 
15             //    int videoTimeLimit = 60;
16             //    cameraCapture.VideoTimeLimit = new TimeSpan(0, 0, videoTimeLimit);
17 
18             //    cameraCapture.Mode = CameraCaptureMode.Still;
19 
20             //    // Specify still quality
21             //    cameraCapture.StillQuality = CameraCaptureStillQuality.High;
22 
23             //    cameraCapture.VideoTypes = CameraCaptureVideoTypes.Standard;
24 
25             //    object cameraEnabled = Microsoft.WindowsMobile.Status.SystemState.GetValue(Microsoft.WindowsMobile.Status.SystemProperty.CameraEnabled);
26             //    if (null != cameraEnabled && 0 == (int)cameraEnabled)
27             //    {
28             //        MessageBox.Show("摄像头不可用!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
29             //        return;
30             //    }
31 
32 
33             //    // Displays the "Camera Capture" dialog box
34             //    if (DialogResult.OK == cameraCapture.ShowDialog())
35             //    {
36             //        string fileName = cameraCapture.FileName;
37 
38             //        // If it is a video we rename the file so that it has the user entered default filename and the correct extension.
39             //        if (cameraCapture.Mode == CameraCaptureMode.Still)
40             //        {
41             //            string filepath;
42             //            filepath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
43             //            if (filepath != "\\")
44             //            {
45             //                filepath += "\\";
46             //            }
47             //            filepath += "Photo\\";
48             //            Application.DoEvents();
49             //            if (!Directory.Exists(filepath))
50             //            {
51             //                Application.DoEvents();
52             //                Directory.CreateDirectory(filepath);
53             //            }
54             //            Application.DoEvents();
55 
56             //            string extension = fileName.Substring(fileName.LastIndexOf("."));
57             //            string directory = "";
58             //            //if (fileName.LastIndexOf("\\") != -1)
59             //            //{
60             //            //    directory = fileName.Substring(0, fileName.LastIndexOf("\\") + 1);
61             //            //}
62             //            fileName = filepath + "" + "QS_" + tbydh.Text.Trim() + "" + DateTime.Now.ToString() + "" + extension;
63 
64             //            fileName = fileName.Replace(":", "-");
65             //            // 图片名称
66             //            //string fileName = "ZDCamera.jpg";
67             //            if (System.IO.File.Exists(fileName))
68             //            {
69             //                System.IO.File.Delete(fileName);
70             //            }
71 
72             //            System.IO.File.Move(cameraCapture.FileName, fileName);
73             //            GC.Collect();
74             //        }
75             //        //// The method completed successfully.
76             //        //MessageBox.Show("The picture or video has been successfully captured and saved to:\n\n" + fileName, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
77             //    }
78             //}
79             //catch (ArgumentException ex)
80             //{
81             //    // An invalid argument was specified.
82             //    MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
83             //}
84             //catch (OutOfMemoryException ex)
85             //{
86             //    // There is not enough memory to save the image or video.
87             //    MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
88             //}
89             //catch (InvalidOperationException ex)
90             //{
91             //    // An unknown error occurred.
92             //    MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
93             //}
94             //finally
95             //{
96             //    GlobalCache.Instance.myWin32.AddHookList();//添加钩子
97             //} 
View Code
        /// <summary>
        /// 取消所有屏蔽的键值
        /// </summary>
        /// <returns></returns>
        public bool DeHook()
        {
            bool retKeyboard = true;
            if (hHook != (IntPtr)0)
            {
                retKeyboard = Win32.UnhookWindowsHookEx(hHook);
                hHook = (IntPtr)0;
                HookHT.Clear();
            }
            return true;
        }


     /// <summary>
        /// 将一个键值添加到钩子列表
        /// </summary>
        /// <param name="nKeyValue"></param>
        public void AddHookKeyValueToList(int nKeyValue)
        {
            if (HookHT == null)
            {
                HookHT = new Hashtable();
            }
            if (!HookHT.ContainsKey(nKeyValue))
            {
                HookHT.Add(nKeyValue, 0);
            }
        }
View Code
heyanan的主页 heyanan | 初学一级 | 园豆:63
提问于:2013-11-26 10:33
< >
分享
所有回答(2)
1

你还在w Mobile啊,向您致敬!

jerry-Tom | 园豆:4077 (老鸟四级) | 2013-11-26 10:39

是呢,还在弄这个。

支持(0) 反对(0) heyanan | 园豆:63 (初学一级) | 2013-11-26 10:41
0

把调用拍照的代码单独放在一个界面在需要调用拍照时调用拍照界面,经测试暂时没有发现拍照假死情况。

heyanan | 园豆:63 (初学一级) | 2013-11-27 11:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册