Sheamus
Sheamus

Reputation: 223

Converting System.Drawing.Image to System.Data.Linq.Binary

I'm working on a application storing images in DB. The images are related to an object and I have to use Linq for this. When I insert the object in database, its image is a System.Drawing.Image, which needs to be converted in System.Data.Linq.Binary.

I found tutos for the other way but not for this one.

Upvotes: 3

Views: 3549

Answers (1)

Denis Palnitsky
Denis Palnitsky

Reputation: 18387

  using (MemoryStream ms = new MemoryStream())
  {
      image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
      var binary = new System.Data.Linq.Binary(ms.GetBuffer());
  }

Upvotes: 6

Related Questions