C# 使用c sharp捕获图像
我设计了一个c sharp应用程序,在Dynamsoft Dynamic.NET TWAIN 5.3试用版的帮助下,使用笔记本电脑摄像头捕捉图像,保存图像,并通过电子邮件发送副本。。。。当我从visual studio运行程序时,它工作正常,但当我在程序目录外复制并粘贴.exe文件时,它不工作,并显示一条消息“program_name已停止工作”。这是我的代码:C# 使用c sharp捕获图像,c#,dynamic,C#,Dynamic,我设计了一个c sharp应用程序,在Dynamsoft Dynamic.NET TWAIN 5.3试用版的帮助下,使用笔记本电脑摄像头捕捉图像,保存图像,并通过电子邮件发送副本。。。。当我从visual studio运行程序时,它工作正常,但当我在程序目录外复制并粘贴.exe文件时,它不工作,并显示一条消息“program_name已停止工作”。这是我的代码: using System; using System.Linq; using System.Collections.Generic;
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Dynamsoft.DotNet.TWAIN.Enums;
using Dynamsoft.DotNet.TWAIN.WebCamera;
using System.Net.Mail;
using System.IO;
using System.Collections;
namespace captureImageOfMyLaptopUser
{
public partial class Form1 : Form
{
string receiverId;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dynamicDotNetTwain1.IfShowUI = true;
dynamicDotNetTwain1.SupportedDeviceType = EnumSupportedDeviceType.SDT_WEBCAM;
dynamicDotNetTwain1.IfThrowException = true;
if (!Directory.Exists("d:\\WhoOpenedMyLaptop\\Images"))
{
Directory.CreateDirectory("d:\\WhoOpenedMyLaptop");
}
string[] filePaths = Directory.GetFiles(@"d:\WhoOpenedMyLaptop");
ArrayList list = new ArrayList();
int num=0;
foreach (string path in filePaths)
{
int l = path.Length;
num = int.Parse(path.Substring(24, l - 28));
list.Add(num);
}
int[] array = list.ToArray(typeof(int)) as int[];
if (array.Length > 0)
{
num = array.Max();
}
else
{
num=0;
}
string fileName = "d:\\WhoOpenedMyLaptop\\pic" + (num + 1).ToString() + ".pdf";
turnOnCamera();
captureImage();
saveImage(fileName);
sendingTheImage(fileName);
}
private void captureImage()
{
try
{
dynamicDotNetTwain1.EnableSource();
}
catch (Exception)
{
MessageBox.Show("error");
}
}
private void turnOnCamera()
{
try
{
dynamicDotNetTwain1.SelectSourceByIndex(0) ;
dynamicDotNetTwain1.SetVideoContainer(pictureBox1);
dynamicDotNetTwain1.OpenSource();
int count = dynamicDotNetTwain1.ResolutionForCamList.Count;
for (int j = 0; j < count; j++)
{
string tempHeight = dynamicDotNetTwain1.ResolutionForCamList[j].Height.ToString();
string tempWidth = dynamicDotNetTwain1.ResolutionForCamList[j].Width.ToString();
string tempResolution = tempWidth + "X" + tempHeight;
comboResolution.Items.Insert(j, tempResolution);
comboResolution.SelectedIndex = 0;
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
private void saveImage(string imagePath)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.FileName = imagePath;
saveFileDialog.Filter = "pdf files (*.pdf)|*.pdf|All files (*.*)|*.*";
dynamicDotNetTwain1.SaveAllAsPDF(saveFileDialog.FileName);
}
private void sendingTheImage(string path)
{
readEmailIdFromTextFile();
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("seewhoopenedyourlaptop@gmail.com");
mail.To.Add(receiverId);
string date = DateTime.Now.ToString();
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(path);
mail.Attachments.Add(attachment);
mail.Subject = "لقد قام هذا الشخص بفتح جهازك ";
mail.Body = "التوقيت : " + date;
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("seewhoopenedyourlaptop", "mylaptopcamera");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
// MessageBox.Show("mail Send");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void readEmailIdFromTextFile()
{
String line;
StreamReader sr = new StreamReader("C:\\Program Files\\WhoOpenedMyLaptop\\data.txt");
line = sr.ReadLine();
receiverId = line;
sr.Close();
}
}
使用系统;
使用System.Linq;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用系统文本;
使用System.Windows.Forms;
使用Dynamsoft.DotNet.TWAIN.Enums;
使用Dynamsoft.DotNet.TWAIN.WebCamera;
使用System.Net.Mail;
使用System.IO;
使用系统集合;
命名空间captureImageOfMyLaptopUser
{
公共部分类Form1:Form
{
字符串接收方;
公共表格1()
{
初始化组件();
}
私有void Form1\u加载(对象发送方、事件参数e)
{
dynamicDotNetTwain1.IfShowUI=true;
DynamicNotNettwain1.SupportedDeviceType=EnumSupportedDeviceType.SDT_网络摄像头;
DynamicNotNettwain1.IfThrowException=true;
如果(!Directory.Exists(“d:\\WhoOpenedMyLaptop\\Images”))
{
目录.CreateDirectory(“d:\\WhoOpenedMyLaptop”);
}
string[]filepath=Directory.GetFiles(@“d:\WhoOpenedMyLaptop”);
ArrayList=新建ArrayList();
int num=0;
foreach(文件路径中的字符串路径)
{
int l=路径长度;
num=int.Parse(path.Substring(24,l-28));
列表。添加(num);
}
int[]数组=list.ToArray(typeof(int))作为int[];
如果(array.Length>0)
{
num=array.Max();
}
其他的
{
num=0;
}
字符串fileName=“d:\\WhoOpenedMyLaptop\\pic”+(num+1).ToString()+”.pdf”;
turnOnCamera();
captureImage();
保存图像(文件名);
发送图像(文件名);
}
私有void captureImage()
{
尝试
{
dynamicDotNetTwain1.EnableSource();
}
捕获(例外)
{
MessageBox.Show(“错误”);
}
}
私有无效turnOnCamera()
{
尝试
{
DynamicNotNettwain1.选择SourceByIndex(0);
dynamicdotnetwain1.SetVideoContainer(pictureBox1);
dynamicDotNetTwain1.OpenSource();
int count=dynamicDotNetTwain1.ResolutionForCamList.count;
对于(int j=0;j
}您应该将可执行文件与所有dll文件一起复制,因为这取决于它们。您可以转到“引用”,然后选择所有库,并在atributes,更改为“始终复制”,然后清理项目,然后生成项目,不运行,将文件夹的所有内容复制到新位置并打开可执行文件,它应该运行exe不会单独运行,您必须复制已放置所有dll的所有输出文件夹s@Boulis制作安装程序。我认为这是使用该库的限制之一,如果你想了解这条信息,你不应该使用试用版。购买动态软件怎么样?我想是的。搜索