I'm having trouble consistently setting the width and height of an img tag. The img src is pulled dynamically from a database. The images being pulled from the database can have varying widths and heights so I need to set the img control. Sometimes the width and height are set properly and sometimes they aren't. I can't figure out why. Any help would be greatly appreciated. Thanks!
Here is what I'm doing now.
try
{
byte[] byteArray = GetImage();
using (Bitmap bmp = ByteArrayToBitmap(byteArray))
{
//image is the img tag.
image.Style["width"] = bmp.Width.ToString();
image.Style["height"] = bmp.Height.ToString();
}
}
catch (Exception ex)
{ }
EDIT: This appears to be a problem only in IE. Chrome and Firefox seem to be working fine. Also, when IE7 doesn't display the image with the proper height/width if the browser is refreshed it then displays properly. Sometimes...