Convert System.Drawing.Image to Binary

Results 1 to 2 of 2

Thread: Convert System.Drawing.Image to Binary

  1. #1
    Join Date
    Dec 1969

    Default Convert System.Drawing.Image to Binary

    I am getting the following error: <BR><BR>Compiler Error Message: BC30311: Value of type &#039;System.Drawing.Image&#039; cannot be converted to &#039;1-dimensional array of Byte&#039;.<BR><BR>Does anyone know how to convert the System.Drawing.Image to binary so I can display it with BinaryWrite?<BR><BR><BR><BR>Below is my code:<BR><BR>
     <BR><BR>&#060;%@Import Namespace="System.Drawing.Imaging" %&#062;<BR>&#060;%@ Import Namespace="System.Data.OleDb" %&#062;<BR>&#060;%@ Import Namespace="System.IO" %&#062;  <BR>&#060;%@ Import Namespace="System.Drawing" %&#062; <BR><BR><BR>&#060;script language="VB" runat="server"&#062;<BR>Sub Page_Load(sender as Object, e as EventArgs)<BR>dim dbconn<BR>dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("carshowroom.mdb"))<BR>dbconn.Open()<BR>Dim ivinID<BR>Dim sql<BR>Dim dbcomm<BR>Dim rs<BR>Dim tblVEHICLES<BR>Dim width<BR>Dim height<BR>Dim inp<BR>ivinID = Request.QueryString("vinnum")<BR>sql="SELECT PHOTO1 FROM tblVEHICLES WHERE VIN LIKE " & "&#039;" & ivinID & "&#039;"<BR><BR>rs.Open (sql, dbconn) <BR><BR>Dim fullSizeImg as System.Drawing.Image<BR>Dim thumb as System.Drawing.Image<BR><BR>Try<BR>fullSizeImg = System.Drawing.Image.FromStream(rs("photo1"))<BR>Catch<BR>fullSizeImg = System.Drawing.Image.FromFile("error.gif")<BR>End Try<BR> <BR>        If Request.QueryString("width") = Nothing Then<BR>            width = fullSizeImg.Width  <BR>        ElseIf Request.QueryString("width") = 0 Then  <BR>            width = 320<BR>        Else<BR>            width = Request.QueryString("width") <BR>        End If<BR><BR>        If Request.QueryString("height") = Nothing Then<BR>            height = fullSizeImg.Height <BR>        ElseIf Request.QueryString("height") = 0 Then <BR>            height = 240<BR>        Else<BR>            height = Request.QueryString("height") <BR>        End If<BR> <BR> Response.ContentType = "image/jpeg"<BR> <BR>    thumb = fullSizeImg.GetThumbnailImage(width, height, Nothing, inp)<BR> <BR> <BR> <BR>    Response.BinaryWrite(thumb)<BR><BR> <BR>rs.Close()<BR>dbconn.Close()<BR>end sub<BR>&#060;/script&#062;<BR><BR><BR><BR><BR>
    <BR><BR>I really need to get this working soon -- all help is appreciated!<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Convert System.Drawing.Image to Binary

    Use a BinaryFormatter to serialze the Image to a MemoryStream. Then call GetBuffer on the MemoryStream and it will return a byte array.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts