i am loading images to my app using this piece of code and it doesn't show the image correctly
Image [] img = new Image[100];
int i=0 ;
while (reader.Read())
{
string filePath = (string)reader["Path"];
byte[] transactionContext = (byte[])reader["TransactionContext"];
SqlFileStream sqlFileStream = new SqlFileStream(filePath, transactionContext, FileAccess.Read);
byte[] data = new byte[(int)sqlFileStream.Length];
sqlFileStream.Read(data, 0, Convert.ToInt32(sqlFileStream.Length));
sqlFileStream.Close();
MemoryStream ms = new MemoryStream();
ms.Write(data, 0, data.Length);
img[i] = byteArrayToImage(ms);
ms.Seek(0, SeekOrigin.Begin);
ms.Dispose();
ms.Close();
ms = null;
data = null;
i++;
}
and byteArrayToImage method :
public Image byteArrayToImage(MemoryStream ms)
{
Image returnImage = Image.FromStream(ms);
return returnImage;
}
but when i save them on the disk using this code it works perfectly :
Image [] img = new Image[100];
int i=0 ;
while (reader.Read())
{
string filePath = (string)reader["Path"];
byte[] transactionContext = (byte[])reader["TransactionContext"];
SqlFileStream sqlFileStream = new SqlFileStream(filePath, transactionContext, FileAccess.Read);
byte[] data = new byte[(int)sqlFileStream.Length];
sqlFileStream.Read(data, 0, Convert.ToInt32(sqlFileStream.Length));
sqlFileStream.Close();
string filename = @"D:\Temp\pic" + i.ToString()+".jpeg";
i++;
System.IO.FileStream fs = new System.IO.FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Write);
fs.Write(data, 0, data.Length);
fs.Flush();
fs.Close();
}