下面是一些代码,我已经写在C#这样做(这是从Web API方法)
public void viewLatestImageUpload(int imageType)
{
Context.Response.ContentType = "image/jpeg";
Stream strm = ShowAlbumImage(imageType);
byte[] buffer = new byte[8192];
int byteSeq = strm.Read(buffer, 0, 8192);
while (byteSeq > 0)
{
Context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 8192);
}
}
下面是从数据库中拉图像的方法:
public Stream ShowAlbumImage(int imageType)
{
SqlConnection myConnection = getEtechConnection();
string sql;
if (imageType == 1)
{
sql = "SELECT TOP 1 Img_stream from EquipmentImages ORDER BY CreatedOn DESC";
}
else
{
sql = "SELECT TOP 1 Receipt from ETechReceiptImg ORDER BY StrtDate DESC, StrtTime DESC";
}
SqlCommand cmd = new SqlCommand(sql, myConnection);
cmd.CommandType = CommandType.Text;
myConnection.Open();
object img = cmd.ExecuteScalar();
try
{
return new MemoryStream((byte[])img);
}
catch
{
return null;
}
finally
{
myConnection.Close();
}
}
谢谢为了这。这可以转移到Xamarin和MySQL和PHPMyAdmin使用 –
我会这样认为。一些SQL可能需要进行调整,因为语法略有不同。至少这应该给你一些工作。它会加载到要显示它的页面上下文中。 –