Ejemplo n.º 1
0
Archivo: WiaCopy.cs Proyecto: rasch/SO
        public static void TransferJpgItem(Item item, string path)
        {
            var itemName = item.Properties["Item Name"].get_Value();
            if (!item.Formats.Cast<string>().Contains(FormatID.wiaFormatJPEG))
            {
                Console.WriteLine("Unexpected formats for item {0}, skipping.", itemName);
                return;
            }

            var targetName = itemName + ".jpg";
            Directory.CreateDirectory(path);
            ImageFile file = (ImageFile)item.Transfer(FormatID.wiaFormatJPEG);
            Console.WriteLine("Copying {0}", targetName);
            file.SaveFile(Path.Combine(path, targetName));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Transfers an image from the capture device
        /// </summary>
        private static WiaResult TransferImage(Item item, WiaFormat format, string outputPath, out string fileName)
        {
            fileName = string.Empty;
            try
            {
                //Initiate transfer
                ImageFile image = item.Transfer(format.ComGuid) as ImageFile;

                if (image != null)
                    //Ensure something was obtained.
                {
                    string tempFileName = string.Format("{0}.{1}", Guid.NewGuid().ToString(), format.FileExtension);

                    if (!outputPath.EndsWith("\\"))
                    {
                        outputPath += "\\";
                    }

                    tempFileName = outputPath + tempFileName;

                    image.SaveFile(tempFileName);

                    //An exception will be thrown if the image cannot be saved, by getting here
                    //we know that the save succeeded.
                    fileName = tempFileName;

                    //If the image was not saved in Jpg format then transcode it here
                    if (!WiaFormats.IsJpg(format.ComGuid))
                    {
                        string transcodedFileName;
                        WiaResult transcodeResult = TranscodeImageToJpg(fileName, out transcodedFileName);

                        if (!transcodeResult.Succeeded)
                        {
                            return transcodeResult;
                        }
                        else
                        {
                            fileName = transcodedFileName;
                        }
                    }
                    return WiaResult.Success;
                }
                else
                {
                    return new WiaResult(string.Format(ERROR_MESSAGE_FORMAT,
                        "transfer the image from the device",
                        "The image returned could not be cast to an ImageFile interface"));
                }
            }
            catch (COMException ce)
            {
                if (logger.IsDebugEnabled)
                {
                    logger.Debug(WiaConstants.LoggingConstants.ExceptionOccurred, ce);
                }
                return new WiaResult(string.Format(ERROR_MESSAGE_FORMAT,
                    "transfer the image from the device",
                    WiaError.GetErrorMessage(ce)));
            }
        }
Ejemplo n.º 3
0
        private List<Image> GetPagesFromScanner(ScanSource source, Item item)
        {
            SetDeviceProperty(ref _device, 3088, (int)source);

            List<Image> images = new List<Image>();

            int handlingStatus = GetDeviceProperty(ref _device, WIA_DPS_DOCUMENT_HANDLING_STATUS);
            if ((source == ScanSource.DocumentFeeder && handlingStatus == FEED_READY) || (source == ScanSource.Flatbed && handlingStatus == FLATBED_READY))
            {
                do
                {
                    ImageFile wiaImage = null;
                    try
                    {
                        wiaImage = item.Transfer(WIA_FORMAT_JPEG);
                    }
                    catch (COMException ex)
                    {
                        if ((uint)ex.ErrorCode == WIA_ERROR_PAPER_EMPTY)
                            break;
                        else
                            throw;
                    }

                    if (wiaImage != null)
                    {

                        System.Diagnostics.Trace.WriteLine(String.Format("Image is {0} x {1} pixels", (float)wiaImage.Width / 150, (float)wiaImage.Height / 150));
                        Image image = ConvertToImage(wiaImage);
                        images.Add(image);
                    }
                }
                while (source == ScanSource.DocumentFeeder);
            }
            return images;
        }
Ejemplo n.º 4
0
 public object ShowTransfer(Item Item, string FormatID = "{00000000-0000-0000-0000-000000000000}", bool CancelError = false)
 {
     return Item.Transfer(FormatID);
 }