A set of technologies in .NET for building web applications and web services. Miscellaneous topics that do not fit into specific categories.
You can do it like this:
Say this markup (button + image)
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Show Image" Width="127px" />
<br />
<br />
<asp:Image ID="Image1" runat="server" Height="401px" Width="455px" />
And code for the button is this:
protected void Button1_Click(object sender, EventArgs e)
{
DataTable rstData =
General.MyRst("SELECT ID, MineType, MyImage FROM Fighters WHERE ID = 4");
DataRow I = rstData.Rows[0];
Image1.ImageUrl = GetImage((byte[])I["MyImage"], (string)I["MineType"]);
}
string GetImage(byte[] MyImage, string MineType)
{
return $"Data:{MineType};base64,{Convert.ToBase64String(MyImage)}";
}
And the result is this:
Now, in above, I did save in the database the "mine type". your example code did not, so you could pass the file name, and our routine would thus become this:
DataRow I = rstData.Rows[0];
Image1.ImageUrl = GetImage((byte[])I["MyImage"], (string)I["FileName"]);
And the function now becomes this:
string GetImage(byte[] MyImage, string sFile)
{
string sMineType = MimeMapping.GetMimeMapping(sFile);
return $"Data:{sMineType};base64,{Convert.ToBase64String(MyImage)}";
}
the really nice part about above? We can then even use this approach for display of images in a GridView.
Regards,
Albert D. Kallal (Access MVP 2003-2017)
Edmonton, Alberta, Canada