Image Adapter

Sep 21, 2007 at 7:14 AM
We need to create an image adapter that renders PNG in IE6.
Sep 24, 2007 at 2:21 AM
Edited Sep 24, 2007 at 8:23 AM

cblaze22 wrote:
We need to create an image adapter that renders PNG in IE6.


Mmm....just my opinion, but I don't think so.
What you are sugesting here is not to create an adapter to render an existing asp.net control in a "CSS friendly" way, but is more about to create a hack to fix a browser specific problem, which has been already done by other guys.
In the web you can find lots of AlphaImageLoader + Javascript workarounds.

Rasetti
Sep 28, 2007 at 6:33 AM
This is what I used as my adapter to render PNG. Now if I put any PNG as an image, imagebutton, or html image it will render PNG in IE6.

public class HtmlImageControlAdapter : ControlAdapter
{
protected override void Render(HtmlTextWriter writer)
{
HtmlImage oImage = Control as HtmlImage;
string strPath = Page.MapPath(oImage.Src);

if (!strPath.EndsWith(".png", StringComparison.OrdinalIgnoreCase) && // If not a PNG extension...
oImage.Attributes"PNG" != "true") // And not specifically told this is a PNG...
{
base.Render(writer); // Have control render itself
return;
}

string strSrc = oImage.Src;

writer.Write("<!if !lt IE 7>");
base.Render(writer); // Used by non-IE & IE7
writer.Write("<!endif>");

oImage.Style.Add(HtmlTextWriterStyle.Filter, "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + Page.ResolveClientUrl(strSrc) + "',sizingMethod='image')");
oImage.Src = Page.ResolveClientUrl("~/Images/Spacer.gif");

writer.Write("<!--if lt IE 7>");
base.Render(writer); // Used by IE < 7
writer.Write("<!endif-->");
}
}