search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

How to show the recourse image

Asked by Javier
1 year ago.

How to show in resource colunm a resource image stores in database?

this not works

Dim foto As String = Convert.ToBase64String(r("ImagenP"))
res.Columns.Add(New ResourceColumn("<img src=data:image/jpg;base64," & foto & " width='150' height='150' /> "))

Comment posted by Dan Letecky [DayPilot]
1 year ago.

It looks like you are missing quotes around the src attribute value:

Dim foto As String = Convert.ToBase64String(r("ImagenP"))
res.Columns.Add(New ResourceColumn("<img src='data:image/jpg;base64," & foto & "' width='150' height='150' /> "))

You might also consider serving the image using a special url. Then you would only use the image URL. This option lets you set caching headers for the image and improve performance.

Answer posted by javier
1 year ago.

I answer to myself

Private Sub ParkingDP_BeforeResHeaderRender(sender As Object, e As BeforeResHeaderRenderEventArgs) Handles ParkingDP.BeforeResHeaderRender

Dim htm As String = "<img src=data:image/jpg;base64," & Convert.ToBase64String(e.DataItem("ImagenP")) & " width='150' height='100' /> "
e.Columns(1).Html = htm

End Sub

c#
private void ParkingDP_BeforeResHeaderRender(object sender, BeforeResHeaderRenderEventArgs e)
{
string htm = "<img src=data:image/jpg;base64," + Convert.ToBase64String(e.DataItem("ImagenP")) + " width='150' height='100' /> ";
e.Columns[1].Html = htm;
}

Comment posted by Dan Letecky [DayPilot]
1 year ago.

Thanks for posting your solution!

Comment posted by Javier
1 year ago.

You might also consider serving the image using a special url.??
what do you mean by special url?
save the image in an application folder and address it by link?

Comment posted by Dan Letecky [DayPilot]
1 year ago.

Yes, you can serve it as a static file (add it to the application folder). That would be the easiest way.

If that is not possible, you can also serve it from the database by writing the content to the Response as described here:
https://stackoverflow.com/questions/2253228/asp-net-return-image-from-aspx-link

If you add the Expires header it will be cached by the browser and served faster next time:
https://stackoverflow.com/questions/2608739/how-to-specify-http-expiration-header-asp-net-mvciis/6443000#6443000

This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.