I want to re-size an asp:image using code behind. I’m gonna re-size the image depending on its height so it can fit into place. So far i have
Image img1 = ((Image)e.Item.FindControl("prodImage"));
int finalWidth = Convert.ToInt32(img1.Width);
int maxWidth = 20;
if (finalWidth > maxWidth)
{
resize
}
else
{
dont resize
}
I am getting a conversion error because img1.width is a web unit. I tried but couldnt cast as an int or cast the int as a unit.
Thanks to anyone who can help
See this answer from “High Quality Image Scaling C#“.
Here’s the relevant bit of code that you’ll need: