这是我用的,从数据库读取,然后在页面显示,你看看有用吗 Sub readpic() conn = New SqlConnection(strpath) Dim MyCommand As SqlCommand Dim sql As String = "SELECT picdata, lrsj,pictype,picsize FROM bookinfo where bid='" + bid_info + "'or barcode='" + barcode_pic + "'" Dim command As New SqlCommand(sql, conn) conn.Open() Dim dr As SqlDataReader = command.ExecuteReader() If dr.Read() Then Response.ContentType = dr("pictype").ToString() Response.OutputStream.Write(CType(dr("picdata"), Byte()), 0, CInt(dr("picsize")))
Sub readpic()
conn = New SqlConnection(strpath) Dim MyCommand As SqlCommand Dim sql As String = "SELECT picdata, lrsj,pictype,picsize FROM bookinfo where bid='" + bid_info + "'or barcode='" + barcode_pic + "'" Dim command As New SqlCommand(sql, conn)
conn.Open()
Dim dr As SqlDataReader = command.ExecuteReader()
If dr.Read() Then
Response.ContentType = dr("pictype").ToString()
Response.OutputStream.Write(CType(dr("picdata"), Byte()), 0, CInt(dr("picsize")))
End If
conn.Close() End Sub
<img src="showimage.aspx">
{
string s= MakeServerImg()//此处是生成图片的结果由于代码太多我就省略了;
return "<img src='"+s+"'/>";
}
public System.IO.MemoryStream GetImgStream()
{
string strFileName = MakeServerImg();
int BytesRead,intFileLength;
byte[] ByteValues;
System.Drawing.Image imgFullSize;
MemoryStream stmimage;
strFileName = System.Web.HttpContext.Current.Server.MapPath(strFileName); imgFullSize = System.Drawing.Image.FromFile(strFileName); stmimage = new MemoryStream();
imgFullSize.Save(stmimage, System.Drawing.Imaging.ImageFormat.Gif );
return stmimage; }
最终就是生成的图片流
<img src="showimage.aspx">
=========================