hi
I used below code to decrease image size:
public string GetThumbNail(string url)
{
using (System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(url)))
{
using (System.Drawing.Image thumbnail = image.GetThumbnailImage(100, 100, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero))
{
using (MemoryStream memoryStream = new MemoryStream())
{
thumbnail.Save(memoryStream, ImageFormat.Jpeg);
Byte[] bytes = new Byte[memoryStream.Length];
memoryStream.Position = 0;
memoryStream.Read(bytes, 0, (int)bytes.Length);
return "data:image/jpeg;base64," + Convert.ToBase64String(bytes, 0, bytes.Length);
}
}
}
}
public bool ThumbnailCallback()
{
return false;
}
and
<asp:Image ID="Image2" runat="server" CssClass="imgFse" ImageUrl='<%#GetThumbNail(Eval("ImageCover","http://www.Site.com/image/Film/Cover/{0}"))%>'></asp:Image>
but when I run page this error happen:
Server Error in '/' Application.
'http:/www.digimaster.ir/image/Film/Cover/mn457812(3).jpg' is not a valid virtual path.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: 'http:/www.site.com/image/Film/Cover/mn457812(3).jpg' is not a valid virtual path.
Source Error:
Line 72: public string GetThumbNail(string url)
Line 73: {
Line 74: using (System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(url)))
Line 75: {
Line 76:
|
but when I change code like:
ImageUrl='<%#Eval("ImageCover","~/image/film/cover/{0}")%>'>
it worked correctly...
but I want Imageurl be:
"http://www.Site.com/image/Film/Cover/{0}"
Best Regards
Neda