• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >C#教程 > C#实现手机拍照并且保存水印照片

C#实现手机拍照并且保存水印照片

作者:我的名称很霸气 字体:[增加 减小] 来源:互联网 时间:2017-05-28

我的名称很霸气 通过本文主要向大家介绍了c#图片加水印,c#给图片加水印,c#水印,c#图片水印,c#textbox水印等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

图像采集需要调用摄像头就行拍照操作,网上查了一下资料,需要引用以下3个dll。

看一下运行界面

界面都比较low,主要是功能实现。

private void Camera_Load(object sender, EventArgs e)
{
this.btnSave.Enabled = false;
try
{
borderSize = GetBorderSize(this);
captionHeight = GetCaptionHeight(this);
//InitStudent("", "", "");
this.comboBox_SizeMode.Text = "填充(保持比例)";
FilterInfoCollection infos = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if ((infos != null) && (infos.Count > 0))
{
}
else
{
MessageBox.Show("没有视频设备");
}
this.LoadVedio();
this.splitContainer1.Panel2MinSize = 280;
this.splitContainer1.SplitterDistance = this.splitContainer1.Width - this.splitContainer1.Panel2MinSize + 1;
mf = new BorderForm();
mf.Show(this);
//mf.Left = (this.Left + this.splitContainer1.Panel1.Width - mf.Width) / 2;
//mf.Top = (this.Top + this.splitContainer1.Panel1.Height - mf.Height) / 2;
//marLeft = mf.Left - this.Left;
//marTop = mf.Top - this.Top;
Rectangle rtPic = this.pictureBox_Camera.RectangleToScreen(this.pictureBox_Camera.ClientRectangle);
Rectangle rtMF = this.mf.RectangleToScreen(this.mf.ClientRectangle);
if (rtPic == null || rtMF == null || rtPic.Width == 0 || rtMF.Width == 0)
{
return;
}
mf.Left = ((rtMF.Width + rtMF.Left) + (rtPic.Width + rtPic.Left)) / 2;
mf.Top = ((rtMF.Height + rtMF.Top) + (rtPic.Height + rtPic.Top)) / 2;
mf.SizeChanged += new EventHandler(mf_SizeChanged);
mf.LocationChanged += new EventHandler(mf_LocationChanged);
pictureBox_Camera_SizeChanged(sender, e);
//启动连拍
//this.ShootOneTime = 0;
this.timer1.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
</div>
//加载摄像头设备
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;
}
}
</div>
/// <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);
}
}
</div>
//选择摄像装置
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;
}
}
}
</div>
//选择分辨率
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();
}
}
</div>
//设置数据源大小 
private void comboBox_SizeMode_SelectedIndexChanged(object sender, EventArgs e)
{
switch (this.comboBox_SizeMode.Text)
{
case "默认(原始大小)":
this.pictureBox_Camera.SizeMode = PictureBoxSizeMode.Normal;
break;
case "居中(原始大小)":
this.pictureBox_Camera.SizeMode = PictureBoxSizeMode.CenterImage;
break;
case "填充(拉伸图像)":
this.pictureBox_Camera.SizeMode = PictureBoxSizeMode.StretchImage;
break;
case "填充(保持比例)":
this.pictureBox_Camera.SizeMode = PictureBoxSizeMode.Zoom;
break;
}
}
</div>
//保存照片
private void buttonSave_Click(object sender, EventArgs e)
{
try
{
string filename = Path.Combine(Application.StartupPath, "StuImages", "Newstuimages", this.XH + ".JPG");
if (!this.checkBox1.Checked && File.Exists(filename))
{
if (MessageBox.Show("该生已经有照片文件,是否覆盖? ", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
{
//存储到本地
this.pictureBox_tx.Image.Save(filename);
//OnDataChanged(this, new DataEventArgs(string.Format("头像采集(覆盖),学号:{0},姓名:{1},考生号:{2},身份证号:{3}", this.XH, this.XM, this.KSH, this.SFZH)));
this.txtKSH.Focus();
this.txtKSH.SelectAll();
}
else
{
return;
}
}
else
{
this.pictureBox_tx.Image.Save(filename);
//OnDataChanged(this, new DataEventArgs(string.Format("头像采集,学号:{0},姓名:{1},考生号:{2},身份证号:{3}", this.XH, this.XM, this.KSH, this.SFZH)));
this.txtKSH.Focus();
this.txtKSH.SelectAll();
}
this.timer1.Start();
}
catch
{
}
finally
{
//启用下面一行,点击保存后头像会立即启动刷新
//this.timer1.Start();
this



 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • C#实现手机拍照并且保存水印照片
  • C#裁剪,缩放,清晰度,水印处理操作示例
  • C#如何给word文档添加水印
  • C#如何给PDF文件添加水印
  • C#中给Excel添加水印的具体方法
  • C#向图片添加水印的两种不同场景与解决方法
  • C#给图片加水印的简单实现方法
  • c#图片添加水印的实例代码

相关文章

  • 2017-05-28unity实现多点触控代码
  • 2017-05-28浅谈static a[n*m]={0};中static的作用
  • 2017-05-28C#中遍历Hashtable的4种方法
  • 2017-05-28C#实现基于链表的内存记事本实例
  • 2017-05-28C#中把任意类型的泛型集合转换成SQLXML数据格式的实例
  • 2017-05-28C#基础概念二十五问 21-25
  • 2017-05-28c#唯一值渲染实例代码
  • 2017-05-28.Net常见问题之C#中的委托
  • 2017-05-28C#操作读取、写入XML文档的实用方法
  • 2017-05-28c# asp .net 动态创建sql数据库表的方法

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • C#微信公众号与订阅号接口开发示例代码
    • C#图片上传效果实例分析
    • 浅谈C#设计模式之开放封闭原则
    • C#配置文件Section节点处理总结
    • C#数值转换-显式数值转换表(参考)
    • 轻松学习C#的正则表达式
    • C#删除只读文件或文件夹(解决File.Delete无法删除文件)
    • 深入C# 内存管理以及优化的方法详解
    • C#编程实现发送邮件的方法(可添加附件)
    • C#实现的字符串转MD5码函数实例

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有