Home > Mobile >  how to display image in picturebox without saving in local file system in C#?
how to display image in picturebox without saving in local file system in C#?

Time:08-07

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

CodePudding user response:

Based on the following SO answer, you can get the byte[] of the image with (byte[])imgFile.FileData.get_BinaryData():

converting .__comobj WIA to byte[] in C# application

A bitmap can be put as source into the PictureBox.
Therefore the byte[] as to put into a MemoryStream and create a 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;
  • Related