Load a picturebox from a WIA ImageFile?

左心房为你撑大大i 提交于 2019-12-10 23:43:50

问题


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 probably re-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;

回答1:


WIA.ImageFile is a COM object wrapper, not a System.Drawing.Image.

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);


来源:https://stackoverflow.com/questions/6413267/load-a-picturebox-from-a-wia-imagefile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!