Parsi Coders
کار با اسکنر c# - نسخه قابل چاپ

+- Parsi Coders (http://parsicoders.com)
+-- انجمن: Software Development Programming (http://parsicoders.com/forumdisplay.php?fid=37)
+--- انجمن: C# Programming (http://parsicoders.com/forumdisplay.php?fid=55)
+--- موضوع: کار با اسکنر c# (/showthread.php?tid=2183)



کار با اسکنر c# - Ghoghnus - 04-25-2012

ابتدا کلاس را به برنامه اضافه نمائید و سپس آنرا فرا خوانی کنید
کد:
public class ImageAcquisition
    {
        private WIALib.WiaClass WiaClass;
        private WIALib.ItemClass ItemClass;
        private WIALib.CollectionClass CollectionClassDevices;
        private WIALib.CollectionClass CollectionClassPics;
        

        #region SelectDevice
        public bool SelectDevice()
        {
            try
            {
                object selectUsingUI;

                WiaClass = new WIALib.WiaClass();
                CollectionClassDevices = (WIALib.CollectionClass)WiaClass.Devices;

                if (WiaClass.Devices.Count == 0)
                    return false;

                selectUsingUI = System.Reflection.Missing.Value;

                ItemClass = (WIALib.ItemClass)WiaClass.Create(ref selectUsingUI);

                if (ItemClass == null)
                    return false;

                return true;
            }
            catch (System.Exception exp)
            {
                return false;
            }
        }
        #endregion        

        #region Capture
        public System.Drawing.Image Capture()
        {
            try
            {
                CollectionClassPics = ItemClass.GetItemsFromUI(WIALib.WiaFlag.SingleImage, WIALib.WiaIntent.ImageTypeColor) as WIALib.CollectionClass;
                if (CollectionClassPics == null)
                    return null;

                ItemClass = (WIALib.ItemClass)System.Runtime.InteropServices.Marshal.CreateWrapperOfType(CollectionClassPics[0], typeof(WIALib.ItemClass));
                string imageFileName = System.IO.Path.GetTempFileName();
                ItemClass.Transfer(imageFileName, false);
                System.Drawing.Image Image = System.Drawing.Image.FromFile(imageFileName);

                System.Runtime.InteropServices.Marshal.ReleaseComObject(CollectionClassPics[0]);
                return Image;
            }
            catch (System.Exception exp)
            {
                return null;
            }
        }
        #endregion
    }

این هم رش استفاده :
کد:
ImageAcquisition ImageAcquisition = new ImageAcquisition();
ImageAcquisition.SelectDevice();
this.pictureBox.Image = ImageAcquisition.Capture();



RE: کار با اسکنر c# - Amin_Mansouri - 04-25-2012

یه کم بیشتر توضیح میدی؟


RE: کار با اسکنر c# - Ghoghnus - 04-26-2012

گاهی (مثل الان من)نیازه عکس مستقیم از اسکنر خونده بشه و توی برنامه ذخیره بشه!به کمک این مثال میشه اینکار را انجام داد!