//Retrieve an image in Jpg format and store it into a variable.
var imgFile = (ImageFile)ScanerItem.Transfer(FormatID.wiaFormatJPEG);
var Path = @"D:ScanImg.jpg";
// save the image in some path with filename.
imgFile.SaveFile(Path);
pictureBox1.ImageLocation = Path;
基于以下SO答案,您可以使用(byte[])imgFile.FileData.get_BinaryData()
:获得图像的byte[]
转换__comobj WIA到C#应用程序中的byte[]
位图可以作为源放入PictureBox中
因此byte[]
要放入MemoryStream
并创建Bitmap
:
var imgFile = (ImageFile)ScanerItem.Transfer(FormatID.wiaFormatJPEG);
byte[] imageBytes = (byte[])imgFile.FileData.get_BinaryData();
Bitmap image;
using (MemoryStream stream = new MemoryStream(imageBytes))
{
image = new Bitmap(stream);
}
pictureBox1.Image = image;