Kolay gelsin scanner programı yazıyorum tam tarama esnasında aşağıdaki hata kodunu alıyorum. < Resime gitmek için tıklayın > Çok acil bu sorunu çözmem lazım çaresiz kaldım yardımcı olur musunuz. net. framework 4.6 da yazıyorum. __________________ Kodlamanın tamamı
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Microsoft.Office.Interop.Word; using WIA; using System.Runtime.InteropServices; using System.IO; using System.Data.OleDb; using System.Drawing; using System.Drawing.Design; using System.Drawing.Printing; using GulenAdam_tarabeni; using Microsoft.VisualBasic;
namespace SimpleScanningApp { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
try { if (lstListOfScanner.Items.Count>0) { lstListOfScanner.SelectedIndex = 0; } var deviceManager = new DeviceManager();
for(int i=1; i <= deviceManager.DeviceInfos.Count; i++) // Loop Through the get List Of Devices. { if(deviceManager.DeviceInfos.Type!=WiaDeviceType.ScannerDeviceType) // Skip device If it is not a scanner { continue; } lstListOfScanner.Items.Add(deviceManager.DeviceInfos.Properties["Name"].get_Value()); } taramalar(); } catch (COMException ex) { MessageBox.Show(ex.Message); }
private void btnScan_Click(object sender, EventArgs e) { try { var deviceManager = new DeviceManager();
DeviceInfo AvailableScanner = null;
for (int i = 1; i <= deviceManager.DeviceInfos.Count; i++) // Loop Through the get List Of Devices. { if (deviceManager.DeviceInfos.Type != WiaDeviceType.ScannerDeviceType) // Skip device If it is not a scanner { continue; }
var device = AvailableScanner.Connect(); //Connect to the available scanner.
var ScanerItem = device.Items[1]; // select the scanner.
var imgFile = (ImageFile) ScanerItem.Transfer(FormatID.wiaFormatJPEG); //Retrive an image in Jpg format and store it into a variable.
var Path =System.Windows.Forms.Application.StartupPath.ToString() + "\\Scan\\" + textBox1.ToString().Trim() +"_"+DateTime.Now.ToShortDateString()+"_"+DateTime.Now.ToShortTimeString()+".jpg"; // save the image in some path with filename.
< Resime gitmek için tıklayın >
Çok acil bu sorunu çözmem lazım çaresiz kaldım yardımcı olur musunuz. net. framework 4.6 da yazıyorum.
__________________
Kodlamanın tamamı
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word;
using WIA;
using System.Runtime.InteropServices;
using System.IO;
using System.Data.OleDb;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Printing;
using GulenAdam_tarabeni;
using Microsoft.VisualBasic;
namespace SimpleScanningApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void lblListOfScanner_Click(object sender, EventArgs e)
{
}
void taramalar ()
{
dizinIcerigiListView.Items.Clear();
string path = System.Windows.Forms.Application.StartupPath.ToString() + "\\Scan";
string secilenDizin = path;
DizinIceriginiListeyeEkle(secilenDizin);
// string path = Application.StartupPath.ToString() + "\\Scan";
// listBox1.Items.Clear();
//string[] dosyalar = Directory.GetFiles(path);
//foreach (string dosya in dosyalar)
//{
// if (dosya.EndsWith(".jpg") || dosya.EndsWith(".jpeg"))
// listBox1.Items.Add(dosya);
//}
// @"|DataDirectory|\Scan"
}
private void DizinIceriginiListeyeEkle(string dizin)
{
string[] dizindekiKlasorler = Directory.GetDirectories(dizin);
string[] dizindekiDosyalar = Directory.GetFiles(dizin);
foreach (string klasor in dizindekiKlasorler)
{
DirectoryInfo dirInfo = new DirectoryInfo(klasor);
string klasorAdi = dirInfo.Name;
DateTime olsTarihi = dirInfo.CreationTime;
ListViewItem item = new ListViewItem(klasorAdi);
item.SubItems.Add("Klasör");
item.SubItems.Add("");
item.SubItems.Add(olsTarihi.ToString("dd.MM.yyyy HH:mm"));
dizinIcerigiListView.Items.Add(item);
}
foreach (string dosya in dizindekiDosyalar)
{
FileInfo fileInfo = new FileInfo(dosya);
string dosyaAdi = fileInfo.Name;
string dosyayolu = fileInfo.FullName;
long byteBoyut = fileInfo.Length;
DateTime olsTarihi = fileInfo.CreationTime;
kisi k = new kisi();
ListViewItem item = new ListViewItem(dosyaAdi);
k.radı = dosyaAdi;
item.SubItems.Add("Dosya");
k.türü = ("Dosya");
item.SubItems.Add(byteBoyut.ToString());
k.boyutu = byteBoyut.ToString();
item.SubItems.Add(olsTarihi.ToString("dd.MM.yyyy HH:mm"));
k.tarihi = olsTarihi.ToString("dd.MM.yyyy HH:mm");
item.Tag = dosyayolu;
k.adres = dosyayolu;
kisiler.Add(k);
dizinIcerigiListView.Items.Add(item);
}
}
public static bool TcDogrula(string tcKimlikNo)
{
bool returnvalue = false;
if (tcKimlikNo.Length == 11)
{
Int64 ATCNO, BTCNO, TcNo;
long C1, C2, C3, C4, C5, C6, C7, C8, C9, Q1, Q2;
TcNo = Int64.Parse(tcKimlikNo);
ATCNO = TcNo / 100;
BTCNO = TcNo / 100;
C1 = ATCNO % 10; ATCNO = ATCNO / 10;
C2 = ATCNO % 10; ATCNO = ATCNO / 10;
C3 = ATCNO % 10; ATCNO = ATCNO / 10;
C4 = ATCNO % 10; ATCNO = ATCNO / 10;
C5 = ATCNO % 10; ATCNO = ATCNO / 10;
C6 = ATCNO % 10; ATCNO = ATCNO / 10;
C7 = ATCNO % 10; ATCNO = ATCNO / 10;
C8 = ATCNO % 10; ATCNO = ATCNO / 10;
C9 = ATCNO % 10; ATCNO = ATCNO / 10;
Q1 = ((10 - ((((C1 + C3 + C5 + C7 + C9) * 3) + (C2 + C4 + C6 + C8)) % 10)) % 10);
Q2 = ((10 - (((((C2 + C4 + C6 + C8) + Q1) * 3) + (C1 + C3 + C5 + C7 + C9)) % 10)) % 10);
returnvalue = ((BTCNO * 100) + (Q1 * 10) + Q2 == TcNo);
}
return returnvalue;
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
if (lstListOfScanner.Items.Count>0)
{
lstListOfScanner.SelectedIndex = 0;
}
var deviceManager = new DeviceManager();
for(int i=1; i <= deviceManager.DeviceInfos.Count; i++) // Loop Through the get List Of Devices.
{
if(deviceManager.DeviceInfos.Type!=WiaDeviceType.ScannerDeviceType) // Skip device If it is not a scanner
{
continue;
}
lstListOfScanner.Items.Add(deviceManager.DeviceInfos.Properties["Name"].get_Value());
}
taramalar();
}
catch (COMException ex)
{
MessageBox.Show(ex.Message);
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void btnScan_Click(object sender, EventArgs e)
{
try
{
var deviceManager = new DeviceManager();
DeviceInfo AvailableScanner = null;
for (int i = 1; i <= deviceManager.DeviceInfos.Count; i++) // Loop Through the get List Of Devices.
{
if (deviceManager.DeviceInfos.Type != WiaDeviceType.ScannerDeviceType) // Skip device If it is not a scanner
{
continue;
}
AvailableScanner = deviceManager.DeviceInfos;
break;
}
if(lstListOfScanner.SelectedIndex!= -1 ) {
if (TcDogrula(textBox1.Text.Trim()) == true)
{
var device = AvailableScanner.Connect(); //Connect to the available scanner.
var ScanerItem = device.Items[1]; // select the scanner.
var imgFile = (ImageFile) ScanerItem.Transfer(FormatID.wiaFormatJPEG); //Retrive an image in Jpg format and store it into a variable.
var Path =System.Windows.Forms.Application.StartupPath.ToString() + "\\Scan\\" + textBox1.ToString().Trim() +"_"+DateTime.Now.ToShortDateString()+"_"+DateTime.Now.ToShortTimeString()+".jpg"; // save the image in some path with filename.
if (File.Exists(Path))
{
File.Delete(Path);
}
imgFile.SaveFile(Path);
pictureBox1.ImageLocation = Path;
taramalar();
textBox1.Clear();
textBox1.Focus();
}
else
{
MessageBox.Show("T.C. numarası hatalı veya girmedin");
}
}
else
{
MessageBox.Show("Tarayıcı mevcut değil");
}
}
catch(COMException ex)
{
MessageBox.Show(ex.Message);
}
}
private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
}
List<kisi> kisiler = new List<kisi>();
private void TextBox1_TextChanged(object sender, EventArgs e)
{
textBox1.MaxLength = 11;
dizinIcerigiListView.Items.Clear();
List<kisi> listem = kisiler.FindAll(x => x.radı.Contains(textBox1.Text.Trim()));
for (int i = 0; i < listem.Count; i++)
{
kisi u = listem;
ListViewItem li = new ListViewItem(u.radı);
li.SubItems.Add(u.türü);
li.SubItems.Add(u.boyutu);
li.SubItems.Add(u.tarihi);
li.Tag = u.adres;
dizinIcerigiListView.Items.Add(li);
}
}
private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void DizinIcerigiListView_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (dizinIcerigiListView.Items.Count!=0)
{
string resimYolu = dizinIcerigiListView.SelectedItems[0].Tag.ToString();
pictureBox1.ImageLocation = resimYolu;
}
}
catch (Exception)
{
}
}
private void ContextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
}
private void TaramayıSilToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dizinIcerigiListView.Items.Count != 0)
{
string resimYolu = dizinIcerigiListView.SelectedItems[0].Tag.ToString();
//Directory.Delete(resimYolu);
if (System.IO.File.Exists(resimYolu))
{
System.IO.File.Delete(resimYolu);
taramalar();
}
}
}
private void PrintDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
}
void wordeat(string adres)
{ // Word uygulamasını oluşturuyoruz.
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
// Yeni doküman oluşturuyoruz.
WordApp.Documents.Add();
// word açılıyor.
WordApp.Visible = true;
Microsoft.Office.Interop.Word.Document doc = WordApp.ActiveDocument;
// OpenFileDialog ile seçim yapılması sağlanıyor.
doc.InlineShapes.AddPicture(adres);
}
private void YazdırToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dizinIcerigiListView.Items.Count != 0)
{
wordeat(dizinIcerigiListView.SelectedItems[0].Tag.ToString());
// pageSetupDialog1.ShowDialog();
}
// printPreviewDialog1.ShowDialog();
}
private void YenileToolStripMenuItem_Click(object sender, EventArgs e)
{
taramalar();
}
}
}
< Bu mesaj bu kişi tarafından değiştirildi kuzgun155 -- 20 Mayıs 2019; 15:42:49 >