wia Kodak 扫描仪应用 winform
wia
代码
private ImageFile imageFile = null;
private string ScanTemp = ConfigurationSettings.AppSettings["ScanTemp"].ToString().Trim();
private string imgType = "jpg";
private DeviceManager manager = null;
private Device device = null;
private List<System.Drawing.Image> imgs = new List<System.Drawing.Image>();
private List<System.Drawing.Image> StartScan()
{
manager = new DeviceManagerClass();
foreach( DeviceInfo info in manager.DeviceInfos )
{
if( info.Type != WiaDeviceType.ScannerDeviceType ) continue;
device = info.Connect();
break;
}
if( device == null )
{
throw new Exception("扫描仪没连接!");
}
Item item = device.Items[1];
CommonDialogClass cdc = new WIA.CommonDialogClass();
//string formatID = this.GetWiaFormat();
try
{
imageFile = cdc.ShowAcquireImage( WiaDeviceType.ScannerDeviceType, WiaImageIntent.UnspecifiedIntent,
WiaImageBias.MinimizeSize, "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}", true, false, false );
}
catch( System.Runtime.InteropServices.COMException ex)
{
imageFile = null;
//throw new Exception( ex.Message );
}
while( imageFile != null )
{
var buffer = imageFile.FileData.get_BinaryData() as byte[];
using( MemoryStream ms = new MemoryStream() )
{
ms.Write( buffer, 0, buffer.Length );
imgs.Add( System.Drawing.Image.FromStream( ms ) );
}
imageFile = null;
try
{
imageFile = cdc.ShowTransfer( item, "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}", false ) as ImageFile;
}
catch( Exception ex )
{
return imgs;
//throw new Exception( ex.Message );
}
}
return imgs;
}
private string ScanTemp = ConfigurationSettings.AppSettings["ScanTemp"].ToString().Trim();
private string imgType = "jpg";
private DeviceManager manager = null;
private Device device = null;
private List<System.Drawing.Image> imgs = new List<System.Drawing.Image>();
private List<System.Drawing.Image> StartScan()
{
manager = new DeviceManagerClass();
foreach( DeviceInfo info in manager.DeviceInfos )
{
if( info.Type != WiaDeviceType.ScannerDeviceType ) continue;
device = info.Connect();
break;
}
if( device == null )
{
throw new Exception("扫描仪没连接!");
}
Item item = device.Items[1];
CommonDialogClass cdc = new WIA.CommonDialogClass();
//string formatID = this.GetWiaFormat();
try
{
imageFile = cdc.ShowAcquireImage( WiaDeviceType.ScannerDeviceType, WiaImageIntent.UnspecifiedIntent,
WiaImageBias.MinimizeSize, "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}", true, false, false );
}
catch( System.Runtime.InteropServices.COMException ex)
{
imageFile = null;
//throw new Exception( ex.Message );
}
while( imageFile != null )
{
var buffer = imageFile.FileData.get_BinaryData() as byte[];
using( MemoryStream ms = new MemoryStream() )
{
ms.Write( buffer, 0, buffer.Length );
imgs.Add( System.Drawing.Image.FromStream( ms ) );
}
imageFile = null;
try
{
imageFile = cdc.ShowTransfer( item, "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}", false ) as ImageFile;
}
catch( Exception ex )
{
return imgs;
//throw new Exception( ex.Message );
}
}
return imgs;
}
Kodak
代码
try
{
int k = axImgScan1.ShowSelectScanner();//选择扫描仪
int ll_rtn = axImgScan1.OpenScanner(); //打开扫描仪
if( ll_rtn == 0 )
{
if( axImgScan1.ScannerAvailable() == true )//判断扫描仪是否可用
{
//axImgScan1.PageOption = PageOptionConstants.AppendPages;
//axImgScan1.PageType = PageTypeConstants.BlackAndWhite;
//axImgScan1.PageCount = 0;
axImgScan1.MultiPage = true;//是否多页
//axImgScan1.PageCount = axImgScan1.PageCount + 1;
string pathGen = ScanTemp + ScanPageName();// @"c:\abc.tif";
axImgScan1.Image = pathGen;
axImgScan1.FileType = FileTypeConstants.TIFF;//设置文件类型
//axImgScan1.GetPageTypeCompressionInfo( ImageTypeConstants.BlackAndWhite1Bit );
//axImgScan1.GetPageTypeCompressionType( ImageTypeConstants.BlackAndWhite1Bit );
// axImgScan1.CompressionType = CompressionTypeConstants.JPEG;
axImgScan1.ScanTo = ScanToConstants.FileOnly;//.DisplayAndUseFileTemplate;
//axImgScan1.ShowSetupBeforeScan = false;//是否在扫描前显示设置界面
axImgScan1.SetPageTypeCompressionOpts( CompPreferenceConstants.CustomSettings, ImageTypeConstants.TrueColor24bitRGB, CompTypeConstants.Uncompressed, CompInfoConstants.NoCompInfo );
axImgScan1.StopScanBox = false;
axImgScan1.Show();
//axImgScan1.GetCompressionPreference() = CompPreferenceConstants.SmallestFile;
ll_rtn = axImgScan1.StartScan();//开始扫描
if( ll_rtn == 0 )
{
Byte[] filebyte = GetScanFileByte( axImgScan1.Image );
axImgScan1.CloseScanner(); //关闭扫描仪
//axImgEdit1.Image = axImgScan1.Image;
//axImgEdit1.SaveAs( axImgScan1.Image, FileTypeConstants.TIFF, PageTypeConstants.BlackAndWhite, CompressionTypeConstants.NoCompression, CompInfoConstants.NoCompInfo, true );
}
else
{
MessageBox.Show( "扫描仪没有正确连接或扫描控件已破坏,请检查!", "系统提示" );
}
axImgScan1.CloseScanner(); //关闭扫描仪
}
else
{
MessageBox.Show( "扫描仪没有正确连接,请重新设置!", "系统提示" );
}
}
else if( ll_rtn == 9219 )
{
MessageBox.Show( "系统没有安装扫描仪或扫描仪没有正确连接!", "系统提示" );
}
}
catch( Exception ex )
{
MessageBox.Show( ex.Message );
}
{
int k = axImgScan1.ShowSelectScanner();//选择扫描仪
int ll_rtn = axImgScan1.OpenScanner(); //打开扫描仪
if( ll_rtn == 0 )
{
if( axImgScan1.ScannerAvailable() == true )//判断扫描仪是否可用
{
//axImgScan1.PageOption = PageOptionConstants.AppendPages;
//axImgScan1.PageType = PageTypeConstants.BlackAndWhite;
//axImgScan1.PageCount = 0;
axImgScan1.MultiPage = true;//是否多页
//axImgScan1.PageCount = axImgScan1.PageCount + 1;
string pathGen = ScanTemp + ScanPageName();// @"c:\abc.tif";
axImgScan1.Image = pathGen;
axImgScan1.FileType = FileTypeConstants.TIFF;//设置文件类型
//axImgScan1.GetPageTypeCompressionInfo( ImageTypeConstants.BlackAndWhite1Bit );
//axImgScan1.GetPageTypeCompressionType( ImageTypeConstants.BlackAndWhite1Bit );
// axImgScan1.CompressionType = CompressionTypeConstants.JPEG;
axImgScan1.ScanTo = ScanToConstants.FileOnly;//.DisplayAndUseFileTemplate;
//axImgScan1.ShowSetupBeforeScan = false;//是否在扫描前显示设置界面
axImgScan1.SetPageTypeCompressionOpts( CompPreferenceConstants.CustomSettings, ImageTypeConstants.TrueColor24bitRGB, CompTypeConstants.Uncompressed, CompInfoConstants.NoCompInfo );
axImgScan1.StopScanBox = false;
axImgScan1.Show();
//axImgScan1.GetCompressionPreference() = CompPreferenceConstants.SmallestFile;
ll_rtn = axImgScan1.StartScan();//开始扫描
if( ll_rtn == 0 )
{
Byte[] filebyte = GetScanFileByte( axImgScan1.Image );
axImgScan1.CloseScanner(); //关闭扫描仪
//axImgEdit1.Image = axImgScan1.Image;
//axImgEdit1.SaveAs( axImgScan1.Image, FileTypeConstants.TIFF, PageTypeConstants.BlackAndWhite, CompressionTypeConstants.NoCompression, CompInfoConstants.NoCompInfo, true );
}
else
{
MessageBox.Show( "扫描仪没有正确连接或扫描控件已破坏,请检查!", "系统提示" );
}
axImgScan1.CloseScanner(); //关闭扫描仪
}
else
{
MessageBox.Show( "扫描仪没有正确连接,请重新设置!", "系统提示" );
}
}
else if( ll_rtn == 9219 )
{
MessageBox.Show( "系统没有安装扫描仪或扫描仪没有正确连接!", "系统提示" );
}
}
catch( Exception ex )
{
MessageBox.Show( ex.Message );
}
IMGADMIN.OCX
代码
//选择图片显示 axImgAdmin1用法
axImgAdmin1.Image = "";
axImgAdmin1.DialogTitle = "选择一张图片";
axImgAdmin1.Filter = "All Image Files |*.bmp; *.jpg; *.tif|Bitmap Files(*.bmp)|*. bmp|JPG Files (*.jpg)|*.jpg|TIFF Files (*.tif)|*.tif|All Files (*.*)|*.*|";
axImgAdmin1.FilterIndex = 4; //选择默认文件类型,对应Filter
axImgAdmin1.InitDir = "c:\\"; //选择的默认路径
axImgAdmin1.CancelError = false;
axImgAdmin1.ShowFileDialog( AdminLibCtl.DlgOptionValue.OpenDlg );
if( axImgAdmin1.Image == "" )
{
}
else
{
axImgEdit1.Image = axImgAdmin1.Image;
axImgThumbnail1.Image = axImgAdmin1.Image;
axImgEdit1.Display();
//MessageBox.Show( axImgEdit1.PageCount.ToString() );
}
axImgAdmin1.Image = "";
axImgAdmin1.DialogTitle = "选择一张图片";
axImgAdmin1.Filter = "All Image Files |*.bmp; *.jpg; *.tif|Bitmap Files(*.bmp)|*. bmp|JPG Files (*.jpg)|*.jpg|TIFF Files (*.tif)|*.tif|All Files (*.*)|*.*|";
axImgAdmin1.FilterIndex = 4; //选择默认文件类型,对应Filter
axImgAdmin1.InitDir = "c:\\"; //选择的默认路径
axImgAdmin1.CancelError = false;
axImgAdmin1.ShowFileDialog( AdminLibCtl.DlgOptionValue.OpenDlg );
if( axImgAdmin1.Image == "" )
{
}
else
{
axImgEdit1.Image = axImgAdmin1.Image;
axImgThumbnail1.Image = axImgAdmin1.Image;
axImgEdit1.Display();
//MessageBox.Show( axImgEdit1.PageCount.ToString() );
}