Frage

In an ASP.NET app (using framework 2.0), and the ORM for this application is Subsonic 2.2, which I'm working with for the first time.

I have an image which I've retrieved from a URL, and I have an HttpWebresponse object, which I've converted to an image, like this:

    string uri = ...;
    HttpWebRequest lxRequest = (HttpWebRequest) WebRequest.Create(uri);
    HttpWebResponse lxResponse = (HttpWebResponse) lxRequest.GetResponse();
    System.Drawing.Image image = System.Drawing.Image.FromStream(lxResponse.GetResponseStream());

In Sql Server, I've created an Image column (could be any other binary format, that's not a problem), and I'd like to write my image into it. I'd also like to know how to read from the column, so as to test that the image has been correctly saved.

Any help appreciated. Thanks.

War es hilfreich?

Lösung

For a image column, Subsonic creates a byte[] property.

Therefore, you'll have to transform your data (System.Drawing.Image in this case) to and from a byte array.

Other sites have this covered, shamelessly copied:

public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
 MemoryStream ms = new MemoryStream();
 imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
 return  ms.ToArray();
}

public Image byteArrayToImage(byte[] byteArrayIn)
{
     MemoryStream ms = new MemoryStream(byteArrayIn);
     Image returnImage = Image.FromStream(ms);
     return returnImage;
}

Andere Tipps

Have looked at Read and write SQL image data, this might help you

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top