我一直在研究人脸识别系统。 图像处理器使用以下代码:
Bitmap bit = (Bitmap) System.Drawing.Image.FromFile (files [j].FullName, true);
Image <Bgr, Byte> img1 = new Image <Bgr, Byte>(bit); // path can be absolute or relative.
Image <Gray, Byte> grayFrem = img1.Convert <Gray, byte>();
我渲染并接收数据增加并将数据放入字典中。
在我想要实际收入之后:
Img1.Dispose ();
我这样做是因为我想解锁文件,然后在另一个类中执行复制,这是我用来复制的代码。
File.Copy (Path.Combine (path, pic), Path.Combine (backupDir, pic), true);
我仍然得到这个错误:
未处理的异常:System.IO.IOException:进程不能 访问文件'C:\ xxxxxx \ xxxx \ xxx \ 95177.jpg',因为它 被另一个进程使用。
我可以使用其他方法来解锁图像或过程吗?
祝你好运
答案 0 :(得分:1)
在这里,你需要处理MailMessage的对象。
对于前。
// Sends email using SMTP, Uses default network credentials
public static void SendEmail(string To, string From, string BCC, string Subject, string Body, bool IsBodyHtml, string attachedPath = "") {
char[] validSeperators = new char[] { ',', ':', ';' };
string fromEmail = string.Empty;
foreach (char seperator in validSeperators) {
if (!string.IsNullOrEmpty(From) && From.Contains(seperator.ToString())) {
fromEmail = From.Split(seperator)[0];
break;
}
}
//create mail message
MailMessage message = !string.IsNullOrEmpty(fromEmail) ? new MailMessage(fromEmail, To) : new MailMessage(From, To);
if (BCC.Length > 0) {
message.Bcc.Add(BCC);
}
message.IsBodyHtml = IsBodyHtml;
message.Subject = Subject;
message.Body = Body;
// Email Attachment
if (!string.IsNullOrEmpty(attachedPath)) {
Attachment attach = new Attachment(attachedPath);
// Attach the created email attachment
message.Attachments.Add(attach);
}
//create mail client and send email
SmtpClient emailClient = new SmtpClient();
emailClient.Host = SMTPServer;
emailClient.Port = SMTPPort;
emailClient.Credentials = new NetworkCredential(SMTPUserName, SMTPPassword);
emailClient.EnableSsl = EnableSSLForSMTP;
emailClient.Send(message);
//Here you can dispose it after sending the mail.
message.Dispose();
//Remove specific file after sending mail to customer
if (!string.IsNullOrEmpty(attachedPath))
DeleteAttachedFile(attachedPath);
}
//Method to remove attached file from specific path.
private static void DeleteAttachedFile(string attachedPath) {
File.SetAttributes(attachedPath, FileAttributes.Normal);
File.Delete(attachedPath);
}
答案 1 :(得分:0)
你应该处理不是img1。此外,遇到问题时,将所有数据加载到内存中,然后从中创建位图。