Aousaf rashid

Aousaf rashid

  • NA
  • 72
  • 4.7k

No imaging component suitable to complete the operation was

Feb 24 2018 6:19 PM
I'm trying to load image from my .mdb database in WPF.I'm using this code :

public void loadimg()
{
con.Open();
OleDbCommand cmd = new OleDbCommand("Select * from recents", con);
DataTable table = new DataTable;
OleDbDataAdapter adap = new OleDbDataAdapter(cmd);
adap.Fill(table);
if (table.Rows.Count <= 0)
{
MsgBox("nooo");
}
else
{
MemoryStream stream = new MemoryStream();
StreamWriter stm;
BinaryWriter writer = new BinaryWriter(stream);
int bufferSize = 100;
byte[] outByte = new byte[bufferSize + 1];
long retval;
long startIndex = 0;
string pubID = "";
OleDbDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
reader.Read();
while (reader.Read())
{
startIndex = 0;
retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize);
while (retval == bufferSize)
{
writer.Write(outByte);
writer.Flush();
startIndex += bufferSize;
retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize);
}

writer.Write(outByte, 0, (int)retval - 1);
writer.Flush();
}

reader.Close();
con.Close();
stream.Position = 0;
stream.Seek(0, SeekOrigin.Begin);
System.Drawing.Image _Image = System.Drawing.Image.FromStream(stream);
image1.Source = System.Windows.Media.Imaging.BitmapFrame.Create(stream);
}
}

The code above returns an error : No imaging component suitable to complete this operation was found.

I spent hours trying to figure out how to fix it.Any help would be highly appreciate.

Answers (1)