私はasp.net MVCの新機能です。最後の2日間は、cshtml
の画像をSQLデータベースから表示しようとしています。ここで画像はasp.net MVCで表示されませんでした。
は、データベースから画像を取得するための方法である:
public class ProfilePicture:Gateway
{
public byte[] ShowProfilePicture()
{
Query = "SELECT * FROM t_ProfilePicture WHERE UserId='" + 1 + "'";
Command = new SqlCommand(Query, Connection);
Connection.Open();
Reader = Command.ExecuteReader();
byte[] image = null;
while (Reader.Read())
{
image = (byte[])Reader["ProfilePictureFile"];
}
Reader.Close();
Connection.Close();
return image;
}
}
これはバイトのデータを取得するためのHTMLヘルパーコードです&をbase64に変換します
@{
ProfilePicture aProfilePicture = new ProfilePicture();
var image = aProfilePicture.ShowProfilePicture();
string string64 = Convert.ToBase64String(image);
ViewBag.profilePicture = "data:image/png;base64," + string64;
}
そしてここにはあります<img>
タグ:
<img id="profilePicture" src="@ViewBag.profilePicture" alt="profilePicture" />
ほとんどすべてthisなどの利用可能なソリューション。しかし、まだ解決策はありませんでした。
ありがとうございました。
データはデータベースから正常に読み取られます。 –
(U3lzdGVtLkJ5dGVbXQ ==)これは、デバッグ中のstring64値です –
イメージの大きさ。イメージが本当に小さい場合を除き、小さなbase-64文字列値のように見えますか? –