当前位置: 首页>>代码示例>>C#>>正文


C# ItemClass.TakePicture方法代码示例

本文整理汇总了C#中ItemClass.TakePicture方法的典型用法代码示例。如果您正苦于以下问题:C# ItemClass.TakePicture方法的具体用法?C# ItemClass.TakePicture怎么用?C# ItemClass.TakePicture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ItemClass的用法示例。


在下文中一共展示了ItemClass.TakePicture方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartScan

        public List<Image> StartScan()
        {
            //return null;
            wiaManager = new WiaClass();

            wiaDevs = wiaManager.Devices as CollectionClass;

            //if (string.IsNullOrEmpty(DefaultScaner))
            //{

                object selectUsingUI = System.Reflection.Missing.Value;			// = Nothing
                wiaRoot = (ItemClass)wiaManager.Create(ref selectUsingUI);	// let user select device

                if (wiaRoot != null)
                {
                    string selectId = wiaRoot.GetPropById((WiaItemPropertyId)WiaDeviceInfoPropertyId.DeviceInfoDevId) as string;
                    XmlHelper.UpdateConfig("DefaultScan", selectId);
                }
            //}
            else
            {
                foreach (object info in (wiaManager.Devices as CollectionClass))
                {
                    //string selectId = wiaRoot.GetPropById((WiaItemPropertyId)WiaDeviceInfoPropertyId.DeviceInfoDevId) as string;
                    //if (selectId == DefaultScaner)
                    //{

                    //    wiaRoot = (ItemClass)info.Create();
                    //    break;
                    //}
                }
            }

            try
            {
                //wiaManager = new WiaClass();		// create COM instance of WIA manager

                //wiaDevs = wiaManager.Devices as CollectionClass;			// call Wia.Devices to get all devices

                // this call shows the common WIA dialog to let the user select a picture:
                //wiaPics = wiaRoot.GetItemsFromUI(WiaFlag.SingleImage, WiaIntent.ImageTypeColor) as CollectionClass;
                //if (wiaPics == null)
                //{
                //    return null;
                //}

                //string imageFileName = string.Empty;
                //bool takeFirst = true;						// this sample uses only one single picture
                //foreach (object wiaObj in wiaPics)			// enumerate all the pictures the user selected
                //{
                //if (takeFirst)
                //{
                string imageFileName = string.Empty;
                ItemClass wiaObj =(ItemClass) wiaRoot.TakePicture();

                //wiaItem = (ItemClass)Marshal.CreateWrapperOfType(wiaObj, typeof(ItemClass));
                imageFileName = Path.GetTempFileName();				// create temporary file for image
                Cursor.Current = Cursors.WaitCursor;				// could take some time
                //this.Refresh();
                //wiaRoot.TakePicture();
                wiaObj.Transfer(imageFileName, false);			// transfer picture to our temporary file
                Image img = Image.FromFile(imageFileName);	// create Image instance from file
                //takeFirst = false;									// first and only one done.
                imgs.Add(img);

                //}
                //    Marshal.ReleaseComObject(wiaObj);					// release enumerated COM object
                //}
            }
            catch (Exception ee)
            {
                //MessageBox.Show(this, "Acquire from WIA Imaging failed\r\n" + ee.Message, "WIA", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                //Application.Exit();
            }
            finally
            {
                if (wiaItem != null)
                    Marshal.ReleaseComObject(wiaItem);		// release WIA image COM object
                if (wiaPics != null)
                    Marshal.ReleaseComObject(wiaPics);		// release WIA collection COM object
                if (wiaRoot != null)
                    Marshal.ReleaseComObject(wiaRoot);		// release WIA root device COM object
                if (wiaDevs != null)
                    Marshal.ReleaseComObject(wiaDevs);		// release WIA devices collection COM object
                if (wiaManager != null)
                    Marshal.ReleaseComObject(wiaManager);		// release WIA manager COM object
                Cursor.Current = Cursors.Default;				// restore cursor
            }

            return imgs;
            //    ImageFile imageFile;
            //    DeviceManagerClass manager = new DeviceManagerClass();
            //    Device WiaDev = null;
            //    CommonDialogClass devCdc = new WIA.CommonDialogClass();
            //    if (string.IsNullOrEmpty(DefaultScaner))
            //    {
            //        WiaDev = devCdc.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false);
            //        if (WiaDev != null)
            //        {
            //            XmlHelper.UpdateConfig("DefaultScan", WiaDev.DeviceID);
//.........这里部分代码省略.........
开发者ID:youthjoy,项目名称:cshelper,代码行数:101,代码来源:ScanHelperXP.cs


注:本文中的ItemClass.TakePicture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。