Zain
Zain

Reputation: 1266

How to create Stream object directly from Image stored in Data Table?

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

Answers (1)

Tim Schmelter
Tim Schmelter

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

Related Questions