Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C#应用程序中将.uuuu-comobj-WIA转换为字节[]_C#_Byte_Workflow Foundation_Scanning_Wia - Fatal编程技术网

在C#应用程序中将.uuuu-comobj-WIA转换为字节[]

在C#应用程序中将.uuuu-comobj-WIA转换为字节[],c#,byte,workflow-foundation,scanning,wia,C#,Byte,Workflow Foundation,Scanning,Wia,我的C#应用程序中有以下代码。我希望它使用WIA将扫描文档捕获到byte[]变量中,但我无法将\uuu-comobject转换为byte[] private void btnScan_Click(object sender, EventArgs e) { try { var deviceManager = new DeviceManager(); DeviceInfo

我的C#应用程序中有以下代码。我希望它使用WIA将扫描文档捕获到byte[]变量中,但我无法将
\uuu-comobject
转换为byte[]

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[i].Type != WiaDeviceType.ScannerDeviceType) // Skip device If it is not a scanner
                    {
                        continue;
                    }

                    AvailableScanner = deviceManager.DeviceInfos[i];

                    break;
                }

                var device = AvailableScanner.Connect(); //Connect to the available scanner.
                var ScanerItem = device.Items[1]; // select the scanner.
                var imgFile = ScanerItem.Transfer(FormatID.wiaFormatJPEG); //Retrive an image in Jpg format and store it into a variable.


                TypeConverter obj = TypeDescriptor.GetConverter(imgFile.GetType());
                byte[] bt = (byte[])obj.ConvertTo(imgFile, typeof(byte[]));
                MemoryStream ms = new MemoryStream(bt);
                pictureBox1.Image = Image.FromStream(ms);

                //PictureBox1.Image = img;
            }
            catch(COMException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
private void btnScan\u单击(对象发送者,事件参数e)
{
尝试
{
var deviceManager=new deviceManager();
DeviceInfo AvailableScanner=null;

对于(int i=1;i这是它,只需使用WIA.ImageFile,然后使用FileData.get_BinaryData()转换它:


提供的答案被标记为低质量帖子,以供审核。以下是一些指导原则。提供的答案可能是正确的,但可以从解释中获益。仅代码答案不被视为“好”答案。
WIA.ImageFile imagefile = item.Transfer(format) as WIA.ImageFile;
byte[] imageBytes = (byte[])imagefile.FileData.get_BinaryData();