C#

[C#/PDA]PDA에 장착된 카메라를 이용한 사진 촬영 예제 소스

선영아 사랑해 2016. 1. 15. 17:00

WindowsMobile PDA에 장착된 카메라 제어 소스입니다.

카메라 제어는 PDA  제조사와 상관없이 아래의 소스를 이용하여 사용가능합니다.


Windows.Mobile.dll 참조 추가해주세요.


private void button1_Click(object sender, EventArgs e)
{
    CameraCaptureDialog cameraCapture = new CameraCaptureDialog();
   
    cameraCapture.Owner = this;

    cameraCapture.InitialDirectory = @"\My Documents\";//저장경로 설정

    cameraCapture.DefaultFileName = cameraCapture.DefaultFileName + ".jpg";//이미지파일 기본 이름 설정

    cameraCapture.Mode = CameraCaptureMode.Still;//카메라 설정

    cameraCapture.StillQuality = CameraCaptureStillQuality.Default;//화질설정

    object cameraEnabled = Microsoft.WindowsMobile.Status.SystemState.GetValue(Microsoft.WindowsMobile.Status.SystemProperty.CameraEnabled);

    if (null != cameraEnabled && 0 == (int)cameraEnabled)
    {
        MessageBox.Show("The camera is disabled", this.Text,
                MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
        return;
    }

    try
    {
        if (DialogResult.OK == cameraCapture.ShowDialog())
        {
            string fileName = cameraCapture.FileName;

            pictureBox1.Image = new Bitmap(fileName);

            pictureBox1.Show();

            MessageBox.Show("The picture or video has been successfully captured and saved to:\n\n" + fileName,
                this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
        }
    }
    catch (ArgumentException ex)
    {
        // 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);
    }
}