基本信息
源码名称:C#winform实现拍照并存水印图片
源码大小:0.20M
文件格式:.rar
开发语言:C#
更新时间:2016-11-30
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 5 元 
   源码介绍

C#winform实现拍照并存水印图片

//加载摄像头设备
private void LoadVedio()
        {
            FilterInfoCollection infos = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            if ((infos != null) && (infos.Count > 0))
            {
                int index = 0;
                foreach (FilterInfo info in infos)
                {
                    this.cmbCaptureDevice.Items.Add(new DeviceInfo(info.Name, info.MonikerString, index, FilterCategory.VideoInputDevice));
                    index  ;
                }
                this.cmbCaptureDevice.SelectedIndex = 0;
            }
        }
    /// <summary>
        /// 拍照
        /// </summary>
        private void Shoot()
        {
            try
            {
                if (this.pictureBox_Camera.Image != null && (int)this.numericUpDown1.Value > 0 && (int)this.numericUpDown2.Value > 0)
                {
                    Bitmap resultImage = new Bitmap((int)this.numericUpDown1.Value, (int)this.numericUpDown2.Value);
                    Graphics g = Graphics.FromImage(resultImage);
                    g.CopyFromScreen(new Point(this.mf.Location.X   1, this.mf.Location.Y   1), new Point(6, 6   (isWin7 ? 2 : 0)), new Size(resultImage.Size.Width, resultImage.Size.Height - (6   (isWin7 ? 2 : 0))));
                    if (!string.IsNullOrEmpty(XH))
                    {
                        string str = "";
                        if (this.XH != "")
                        {
                            str = this.XH;
                        }
                        else if (this.SFZH != "")
                        {
                            str = this.SFZH;
                        }
                        else if (this.KSH != "")
                        {
                            str = this.KSH;
                        }
                        if (this.checkBox2.Checked)
                        {
                            str = XM   " "   str;
                        }
                        int txtWidth = (int)(g.MeasureString(str, new Font("宋体", 9)).Width * 1.1);
                        Rectangle rec = new Rectangle((resultImage.Width - txtWidth) / 2, resultImage.Height - 16, txtWidth, 15);
                        g.FillRectangle(Brushes.White, rec);
                        StringFormat sf = new StringFormat();
                        sf.LineAlignment = StringAlignment.Center;
                        sf.Alignment = StringAlignment.Center;
                        rec.Height  ;
                        g.DrawString(str, new Font("宋体", 9), Brushes.Black, rec, sf);
                    }
                    this.pictureBox_tx.Image = resultImage;
                }
                else
                {
                    this.pictureBox_tx.Image = null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
//选择摄像装置
private void cmbCaptureDevice_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.cmbCaptureDevice.SelectedItem != null)
            {
                this.cmbDeviceCapability.Items.Clear();
                VideoCaptureDevice device = new VideoCaptureDevice(((DeviceInfo)this.cmbCaptureDevice.SelectedItem).MonikerString);
                for (int i = 0; i < device.VideoCapabilities.Length; i  )
                {
                    VideoCapabilities capabilities = device.VideoCapabilities[i];
                    DeviceCapabilityInfo item = new DeviceCapabilityInfo(capabilities.FrameSize);
                    this.cmbDeviceCapability.Items.Add(item);
                }
                DeviceInfo selectedItem = (DeviceInfo)this.cmbCaptureDevice.SelectedItem;
                if (this.captureAForge != null)
                {
                    this.captureAForge.NewFrame -= new NewFrameEventHandler(this.captureAForge_NewFrame);
                    //this.captureAForge.SnapshotFrame -= new NewFrameEventHandler(this.captureAForge_SnapshotFrame);
                    if (this.captureAForge.IsRunning)
                    {
                        this.captureAForge.SignalToStop();
                    }
                    this.captureAForge.WaitForStop();
                    this.captureAForge = null;
                }
                this.captureAForge = new VideoCaptureDevice(selectedItem.MonikerString);
                this.captureAForge.ProvideSnapshots = true;
                this.captureAForge.NewFrame  = new NewFrameEventHandler(this.captureAForge_NewFrame);
                //this.captureAForge.SnapshotFrame  = new NewFrameEventHandler(this.captureAForge_SnapshotFrame);
                if (this.cmbDeviceCapability.Items.Count > 0)
                {
                    this.cmbDeviceCapability.SelectedIndex = 0;
                }
            }
        }
//选择分辨率
 private void cmbDeviceCapability_SelectedIndexChanged(object sender, EventArgs e)
        {
            string[] strArray = this.cmbDeviceCapability.Text.Trim().Split(new char[] { 'x' });
            int width = int.Parse(strArray[0]);
            int height = int.Parse(strArray[1]);
            if (this.captureAForge != null)
            {
                if (this.captureAForge.IsRunning)
                {
                    this.captureAForge.SignalToStop();
                }
                this.captureAForge.WaitForStop();
                this.captureAForge.DesiredFrameSize = new Size(width, height);
                this.captureAForge.DesiredSnapshotSize = new Size(width, height);

                //this.captureAForge.DesiredFrameRate = 1000;

                this.captureAForge.Start();

            }
        }