Click here to Skip to main content
Click here to Skip to main content

Showing Transparent Image in Browsers

, 28 Feb 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Showing Transparent Image in Browsers

Introduction

Showing .png images in browsers. It is very simple to show images in broswers, but PNG images in IE browsers display with background and other browsers like Firefox showing PNG images with transparancy, because they are supporting.

Browser Outputs

To view broswer output, click here.

Download

To download solution,
click here.

HTML Block

Past below code in form tag of ASP.NET default.aspx page.
<table border="1">
<tr><td><b>Image With Background</b></td><td><b>Image Without Background</b></td></tr>
<tr>
<td align="center"><asp:Literal ID="ltlOne" runat="server"/></td>
<td align="center"><asp:Literal ID="ltlTwo" runat="server"/></td>
</tr>
</table>

Code Part

Past below code in default.aspx.cs page.ShowTransParentImage() function uses div tag with style to show PNG image in Internet Explorer. Check browsers with this code Request.Browser.Browser. If browser is not Internet Explorer, then use simple img tag to show PNG image.

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ShowTransParentImage();            
        }
    }
 
    protected void ShowTransParentImage()
    {
        string sImg = string.Empty;
        try
        {
            string sT1 = "printer.png";
            string sTemp = "<DIV ID=\"oDiv1" + "\" STYLE=\" height:16px; width:16px; filter: progid: DXImageTransform.Microsoft.AlphaImageLoader(src='" + sT1 + "', sizingMethod='scale'); border:0px;\" />";
            sImg = "<img src=\"" + sT1 + "\" border=\"0\"/>";
            ltlOne.Text = sImg;
            if (Request.Browser.Browser == "IE")
            { sImg = sTemp; }
            ltlTwo.Text = sImg;
        }
        catch (Exception ex)
        { }        
    }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

R S Dodiya
Software Developer (Senior)
India India

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.141022.2 | Last Updated 28 Feb 2011
Article Copyright 2011 by R S Dodiya
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid