Reputation: 1266
I am creating Stream object by first writing image on hard disk then creating stream object from its path.
System.Drawing.Image im = (System.Drawing.Image)rw[3]; //rw is row of data table
im.Save("D:\\aaa.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
System.IO.Stream st = System.IO.File.OpenRead("D:\\aaa.jpg");
This is not efficient way to achieve this.. Is there any way so that i can create stream object directly from image stored in data table.
Upvotes: 2
Views: 633
Reputation: 460158
You can use a MemoryStream
:
System.Drawing.Image image = (System.Drawing.Image)rw[3];
using(var memoryStream = new MemoryStream())
{
image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
Upvotes: 5