由於您已經將數據庫與數據庫中的圖像進行了比較,因此我會將整個「應將圖像存儲在數據庫問題」中。我只是在這裏提到它,因爲我確信其他人會對此發表評論,並且指出我不提這不是最好的主意。我會盡我所能回答你的問題。
您可以讓Web服務直接返回圖像。這是相當簡單的...
這是我寫的一個代碼片段,我只是爲了看看你能做到。希望您可以根據自己的需求進行修改。
<WebMethod()> _
Public Function GetImage() As Byte()
Try
Dim outStream As New System.IO.MemoryStream
Dim REturnValue As New System.Drawing.Bitmap(500, 500)
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(REturnValue)
'g.RotateTransform(5)
Dim f As New System.Drawing.Font(System.Drawing.FontFamily.GenericMonospace, 16, Drawing.FontStyle.Regular, Drawing.GraphicsUnit.Point)
Dim b As System.Drawing.Brush = Drawing.Brushes.Lime
g.DrawString("Hello", f, b, 0, 0)
g.DrawString("Would you like to play a game? (Y/N)", f, b, 0, 40)
g.DrawString("> Y", f, b, 0, 80)
g.DrawString("Loading Global Thermonuclear War,", f, b, 0, 120)
g.DrawString("please wait...", f, b, 0, 160)
REturnValue.Save(outStream, System.Drawing.Imaging.ImageFormat.Jpeg)
Return outStream.ToArray()
Catch ex As Exception
Throw New Exception(ex.ToString())
End Try
End Function
,然後顯示圖像的Asp.Net頁面..
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ts As New TestServices
Dim b As System.Drawing.Bitmap
Dim bytes As Byte()
Dim inStream As System.IO.MemoryStream
bytes = ts.GetImage()
inStream = New System.IO.MemoryStream(bytes)
b = New System.Drawing.Bitmap(inStream)
Response.ContentType = "image/jpeg"
b.Save(Response.OutputStream, b.RawFormat)
b.Dispose()
End Sub
呸!沒有使用/結束使用。 -1。 – 2009-08-12 21:30:13