服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - C# - C#实现手机拍照并且保存水印照片

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

2021-12-09 13:38我的名称很霸气 C#

这篇文章主要介绍了C#实现手机拍照并且保存水印照片的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下

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

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

看一下运行界面

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

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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);
}
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//加载摄像头设备
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;
}
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/// <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);
}
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//选择摄像装置
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;
}
}
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//选择分辨率
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();
}
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//设置数据源大小
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;
}
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//保存照片
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.btnsave.enabled = false;
}
}

保存照片可以选择自动覆盖同名照片或者在照片中加入水印效果。

操作时候可以自行拖动长方形的框进行选择拍照

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

以上所述是小编给大家介绍的c#实现手机拍照并且保存水印照片,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!

原文链接:http://www.cnblogs.com/luoxiaozhao/archive/2016/11/11/6054464.html

延伸 · 阅读

精彩推荐
  • C#利用C#实现网络爬虫

    利用C#实现网络爬虫

    这篇文章主要介绍了利用C#实现网络爬虫,完整的介绍了C#实现网络爬虫详细过程,感兴趣的小伙伴们可以参考一下...

    C#教程网11852021-11-16
  • C#SQLite在C#中的安装与操作技巧

    SQLite在C#中的安装与操作技巧

    SQLite,是一款轻型的数据库,用于本地的数据储存。其优点有很多,下面通过本文给大家介绍SQLite在C#中的安装与操作技巧,感兴趣的的朋友参考下吧...

    蓝曈魅11162022-01-20
  • C#C#微信公众号与订阅号接口开发示例代码

    C#微信公众号与订阅号接口开发示例代码

    这篇文章主要介绍了C#微信公众号与订阅号接口开发示例代码,结合实例形式简单分析了C#针对微信接口的调用与处理技巧,需要的朋友可以参考下...

    smartsmile20127762021-11-25
  • C#C#设计模式之Strategy策略模式解决007大破密码危机问题示例

    C#设计模式之Strategy策略模式解决007大破密码危机问题示例

    这篇文章主要介绍了C#设计模式之Strategy策略模式解决007大破密码危机问题,简单描述了策略模式的定义并结合加密解密算法实例分析了C#策略模式的具体使用...

    GhostRider10972022-01-21
  • C#VS2012 程序打包部署图文详解

    VS2012 程序打包部署图文详解

    VS2012虽然没有集成打包工具,但它为我们提供了下载的端口,需要我们手动安装一个插件InstallShield。网上有很多第三方的打包工具,但为什么偏要使用微软...

    张信秀7712021-12-15
  • C#如何使用C#将Tensorflow训练的.pb文件用在生产环境详解

    如何使用C#将Tensorflow训练的.pb文件用在生产环境详解

    这篇文章主要给大家介绍了关于如何使用C#将Tensorflow训练的.pb文件用在生产环境的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考借鉴...

    bbird201811792022-03-05
  • C#三十分钟快速掌握C# 6.0知识点

    三十分钟快速掌握C# 6.0知识点

    这篇文章主要介绍了C# 6.0的相关知识点,文中介绍的非常详细,通过这篇文字可以让大家在三十分钟内快速的掌握C# 6.0,需要的朋友可以参考借鉴,下面来...

    雨夜潇湘8272021-12-28
  • C#深入理解C#的数组

    深入理解C#的数组

    本篇文章主要介绍了C#的数组,数组是一种数据结构,详细的介绍了数组的声明和访问等,有兴趣的可以了解一下。...

    佳园9492021-12-10