Click here to Skip to main content
15,895,799 members
Articles / Web Development / ASP.NET

Program for Format Conversion of An Image

Rate me:
Please Sign up or sign in to vote.
4.40/5 (18 votes)
31 Mar 2010CPOL2 min read 46.7K   2K   33  
.NET provides extensive support for image conversion. Any image can be processed from one format to another. The most common formats which .NET support are .BMP, .EMF, .GIF, .ICO, .JPG, .PNG, .TIF and .WMF.
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Browse an image of type .jpg, .png, or .bmp. Must be less than or equal to 10MB in size:<br />
        <asp:FileUpload ID="fpImage" runat="server" />
        <asp:RequiredFieldValidator ID="reqImage" Display="Dynamic" ControlToValidate="fpImage" style="font:12px verdana;color:Red;vertical-align:middle;" Text="(Required)" runat="server"></asp:RequiredFieldValidator>
        <asp:CustomValidator ID="cvImageType" Display="Dynamic" ControlToValidate="fpImage" OnServerValidate="cvImageType_Validate" style="font:12px verdana;color:Red;vertical-align:middle;" Text="&nbsp;(Image must be any of these types: .jpg, .gif, .png, .bmp, .tif)" runat="server"></asp:CustomValidator>
        <asp:CustomValidator ID="cvImageSize" Display="Dynamic" ControlToValidate="fpImage" OnServerValidate="cvImageSize_Validate" style="font:12px verdana;color:Red;vertical-align:middle;" Text="&nbsp;(Image size must not exceed by 10MB.)" runat="server"></asp:CustomValidator>
        <br /><br />
        Select Resultant Image Format: 
        <asp:DropDownList ID="drpRIF" runat="server">
            <asp:ListItem Text="(Select)" Value="0"></asp:ListItem>
            <asp:ListItem Text=".JPG" Value="1"></asp:ListItem>
            <asp:ListItem Text=".PNG" Value="2"></asp:ListItem>
            <asp:ListItem Text=".BMP" Value="3"></asp:ListItem>
        </asp:DropDownList>
        <asp:RequiredFieldValidator ID="reqDrpRIF" Display="Dynamic" ControlToValidate="drpRIF" InitialValue="0" style="font:12px verdana;color:Red;vertical-align:middle;" Text="(Required)" runat="server"></asp:RequiredFieldValidator>
        <br /><br />
        <asp:Button ID="btnResults" Text="Show Result" OnClick="btnResults_OnClick" runat="server" />
        <br /><br />
        <table cellpadding="0" cellspacing="0" border="0" style="width:800px">
            <tr>
                <td style="width:50%;padding-right:10px;text-align:center;">
                    <h3>Original Image</h3>
                    <asp:Image ID="imgOriginal" Width="380px" Height="380px" runat="server" />
                    <br /><br />
                    Format: <asp:Label ID="lblOIF" runat="server"></asp:Label><br />
                </td>
                <td style="width:50%;padding-left:10px;text-align:center;">
                    <h3>Resultant Image</h3>
                    <asp:Image ID="imgResult" Width="380px" Height="380px" runat="server" />
                    <br /><br />
                    Format: <asp:Label ID="lblRIF" runat="server"></asp:Label><br />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Technical Lead Cherisys Technologies
India India
Senior Software Professional with 13+ years of experience in web/desktop applications development.

Comments and Discussions