⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cecamera.cs

📁 This sample demonstrates how to take pictures and videos using the CameraCaptureDialog managed AP
💻 CS
📖 第 1 页 / 共 3 页
字号:
            {
                // An invalid argument was specified.
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
            catch (OutOfMemoryException ex)
            {
                // There is not enough memory to save the image or video.
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
                    MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
            catch (InvalidOperationException ex)
            {
                // An unknown error occurred.
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
                    MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
        }

        /// <summary>
        /// Checks the selected menu item of "Mode".
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">Event arguments</param>
        private void menuModeStill_Click(object sender, System.EventArgs e)
        {
            for (int i = 0; i < this.menuMode.MenuItems.Count; i++)
            {
                this.menuMode.MenuItems[i].Checked = false;
            }
            this.menuModeStill.Checked = true;

            validateFileNameInput();

            this.checkResolution.Enabled = true;
            this.checkVideoTimeLimit.Checked = false;
            this.checkVideoTimeLimit.Enabled = false;
        }

        /// <summary>
        /// Checks the selected menu item of "Mode".
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">Event arguments</param>
        private void menuModeVideoOnly_Click(object sender, System.EventArgs e)
        {
            for (int i = 0; i < this.menuMode.MenuItems.Count; i++)
            {
                this.menuMode.MenuItems[i].Checked = false;
            }
            this.menuModeVideoOnly.Checked = true;

            validateFileNameInput();

            this.checkResolution.Checked = false;
            this.checkResolution.Enabled = false;
            this.checkVideoTimeLimit.Enabled = true;
        }

        /// <summary>
        /// Checks the selected menu item of "Mode".
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">Event arguments</param>
        private void menuModeVideoWithAudio_Click(object sender, System.EventArgs e)
        {
            for (int i = 0; i < this.menuMode.MenuItems.Count; i++)
            {
                this.menuMode.MenuItems[i].Checked = false;
            }
            this.menuModeVideoWithAudio.Checked = true;

            validateFileNameInput();

            this.checkResolution.Checked = false;
            this.checkResolution.Enabled = false;
            this.checkVideoTimeLimit.Enabled = true;            
        }

        /// <summary>
        /// Verifies the filename to be consistent with the camera mode.
        /// </summary>
        private void validateFileNameInput()
        {
            if (this.menuModeStill.Checked)
            {
                if (textDefaultFileName.Text == null || textDefaultFileName.Text.Length == 0 ||
                    textDefaultFileName.Text.Equals(cecameraDefaultVideoFileName))
                {
                    this.textDefaultFileName.Text = cecameraDefaultPictureFileName;
                }
            }
            else
            {
                if (textDefaultFileName.Text == null || textDefaultFileName.Text.Length == 0 ||
                    textDefaultFileName.Text.Equals(cecameraDefaultPictureFileName))
                {
                    textDefaultFileName.Text = cecameraDefaultVideoFileName;
                }
            }
        }
        
        /// <summary>
        /// Checks the selected menu item of "Still Quality".
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">Event arguments</param>
        private void menuStillQualityDefault_Click(object sender, System.EventArgs e)
        {
            for (int i = 0; i < this.menuStillQuality.MenuItems.Count; i++)
            {
                this.menuStillQuality.MenuItems[i].Checked = false;
            }
            this.menuStillQualityDefault.Checked = true;
        }

        /// <summary>
        /// Checks the selected menu item of "Still Quality".
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">Event arguments</param>
        private void menuStillQualityLow_Click(object sender, System.EventArgs e)
        {
            for (int i = 0; i < this.menuStillQuality.MenuItems.Count; i++)
            {
                this.menuStillQuality.MenuItems[i].Checked = false;
            }
            this.menuStillQualityLow.Checked = true;
        }

        /// <summary>
        /// Checks the selected menu item of "Still Quality".
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">Event arguments</param>
        private void menuStillQualityNormal_Click(object sender, System.EventArgs e)
        {
            for (int i = 0; i < this.menuStillQuality.MenuItems.Count; i++)
            {
                this.menuStillQuality.MenuItems[i].Checked = false;
            }
            this.menuStillQualityNormal.Checked = true;
        }

        /// <summary>
        /// Checks the selected menu item of "Still Quality".
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">Event arguments</param>
        private void menuStillQualityHigh_Click(object sender, System.EventArgs e)
        {
            for (int i = 0; i < this.menuStillQuality.MenuItems.Count; i++)
            {
                this.menuStillQuality.MenuItems[i].Checked = false;
            }
            this.menuStillQualityHigh.Checked = true;
        }

        /// <summary>
        /// Checks the selected menu item of "Video Types".
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">Event arguments</param>
        private void menuVideoTypesAll_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.menuVideoTypes.MenuItems.Count; i++)
            {
                this.menuVideoTypes.MenuItems[i].Checked = false;
            }
            this.menuVideoTypesAll.Checked = true;
        }

        /// <summary>
        /// Checks the selected menu item of "Video Types".
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">Event arguments</param>
        private void menuVideoTypesStandard_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.menuVideoTypes.MenuItems.Count; i++)
            {
                this.menuVideoTypes.MenuItems[i].Checked = false;
            }
            this.menuVideoTypesStandard.Checked = true;
        }

        /// <summary>
        /// Checks the selected menu item of "Video Types".
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">Event arguments</param>
        private void menuVideoTypesMessaging_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.menuVideoTypes.MenuItems.Count; i++)
            {
                this.menuVideoTypes.MenuItems[i].Checked = false;
            }
            this.menuVideoTypesMessaging.Checked = true;
        }

        /// <summary>
        /// Resets all settings as the default value and updates UI.
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">Event arguments</param>
        private void menuReset_Click(object sender, System.EventArgs e)
        {
            this.ResetOptions();
        }

        /// <summary>
        /// Display a message box for program information.
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">Event arguments</param>
        private void menuAbout_Click(object sender, System.EventArgs e)
        {
            MessageBox.Show("CECamera Version 1.0\n\nSimple sample for CameraCaptureDialog.", this.Text);
        }

        /// <summary>
        /// Close self to exit the application.
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">Event arguments</param>
        private void menuExit_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// Resets all settings as the default value and updates UI.
        /// </summary>
        private void ResetOptions()
        {
            // Uncheck all checkboxs to specify the options using the default value
            this.checkInitialDirectory.Checked = false;
            this.checkDefaultFileName.Checked = false;
            this.checkTitle.Checked = false;
            this.checkResolution.Checked = false;            
            this.checkVideoTimeLimit.Checked = false;
            this.checkVideoTimeLimit.Enabled = false;

            // Set the default value for the options
            this.textInitialDirectory.Text = cecameraDefaultInitialDirectory;
            this.textDefaultFileName.Text = cecameraDefaultPictureFileName;
            this.textTitle.Text = cecameraDefaultTitle;
            this.textResolutionWidth.Text = cecameraDefaultResolutionWidth;
            this.textResolutionHeight.Text = cecameraDefaultResolutionHeight;
            this.textVideoTimeLimit.Text = cecameraDefaultVideoTimeLimit;

            // Disable the edit controls since specify using default settings
            this.textInitialDirectory.Enabled = false;
            this.textDefaultFileName.Enabled = false;
            this.textTitle.Enabled = false;
            this.textResolutionWidth.Enabled = false;
            this.textResolutionHeight.Enabled = false;
            this.textVideoTimeLimit.Enabled = false;

            // Checks the menu item of "Mode" as default item
            for (int i = 0; i < this.menuMode.MenuItems.Count; i++)
            {
                this.menuMode.MenuItems[i].Checked = false;
            }
            this.menuModeStill.Checked = true;

            // Checks the menu item of "Still Quality" as default item
            for (int i = 0; i < this.menuStillQuality.MenuItems.Count; i++)
            {
                this.menuStillQuality.MenuItems[i].Checked = false;
            }
            this.menuStillQualityDefault.Checked = true;

            // Checks the menu item of "Video Types" as default item
            for (int i = 0; i < this.menuVideoTypes.MenuItems.Count; i++)
            {
                this.menuVideoTypes.MenuItems[i].Checked = false;
            }
            this.menuVideoTypesAll.Checked = true;
        }

        /// <summary>
        /// Converts the string to an integer.
        /// </summary>
        /// <param name="value">A string to convert</param>
        /// <param name="result">A integer of the converted result</param>
        /// <returns>true if converts successfully; otherwise, false.</returns>
        private static bool ConvertStringToInt(string value, ref int result)
        {
            try
            {
                result = Convert.ToInt32(value, NumberFormatInfo.CurrentInfo);
            }
            catch (FormatException)
            {
                return false;
            }
            catch (OverflowException)
            {
                return false;
            }

            return true;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -