Reputation: 1285
Could someone please point me to a tutorial/page that will explain how to view a binary image from a database (or if its simple please tell me)?
I'm using cshtml and can query the database but the image part has got me stumped.
Thank you
Upvotes: 0
Views: 138
Reputation: 1
I use this in foto.cshtml Razor I have fotos and thumbnails in he database. This is for the thumbnails.
@{
// Cache the image for a minute
Response.OutputCache(60);
var fotoId = UrlData[0].AsInt();
var db = Database.Open("albums");
var foto = db.QuerySingle("SELECT * FROM Fotos WHERE Id = @0", fotoId);
if (foto == null){
Response.Redirect("~/");
}
new WebImage(foto.Mini).Write();
//Geef maximale breedte en hoogte aan
//var width = 120;
//var height = 60;
//var image = new WebImage(foto.Mini);
//image.Write();//Or image.Resize(width, height).Write();
}
Upvotes: 0
Reputation: 1285
I found a way and hope this helps anyone with the same question.
I created a querySingle to return my image binary data in 'var=file'. I then created the following string variables:
string imageBase64 = Convert.ToBase64String(file.FileContent);
string imageSrc = string.Format("data:image/png;base64,{0}", imageBase64);
*FileContent being my binary data.
And finally created the img:
<img src="@imageSrc" alt="@file.FileName" />
Please up-mark if you find this helpful.
Upvotes: 0