问题描述
我已经从一位同事那里接手了一个设计不佳的项目,并希望直接从WIA命令直接加载一个图片框,而该命令刚刚完成,可以从连接的USB相机拍摄图片.
I've taken over a poorly designed project from a co-worker and am looking to load a picture box directly from the WIA command that just completed to take a picture from an attached USB camera.
当前实现会等到文件已写入磁盘,然后从那里显示它从磁盘重新读取文件.
The current implementation waits until the file has been written to disk, then displays it from there probablyre-reading the file from disk.
Item item = d.ExecuteCommand(WIA.CommandID.wiaCommandTakePicture);
WIA.ImageFile imagefile = item.Transfer(FormatID.wiaFormatJPEG) as WIA.ImageFile;
我尝试将图像投射到给定的图片框上
I tried casting an Image to the given picture box without success
picBox.Image = (Image)imageFile;
推荐答案
WIA.ImageFile是COM对象包装,而不是System.Drawing.Image.
WIA.ImageFile is a COM object wrapper, not a System.Drawing.Image.
您将不得不使用带有临时文件的WIA.ImageFile Save方法,或者尝试如下所示的内存中解决方案: http://www.pcreview.co.uk /forums/wia-imagefile-system-drawing-image-t2321026.html
You'll have to mess with WIA.ImageFile Save method with temporary files or try in-memory solution as shown here:http://www.pcreview.co.uk/forums/wia-imagefile-system-drawing-image-t2321026.html
var imageBytes = (byte[])image.FileData.get_BinaryData();
var ms = new MemoryStream(imageBytes);
var img = Image.FromStream(ms);
这篇关于从WIA ImageFile加载图片框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!