Friday 7 December 2012

Create ThumbnailImage Using ASP.net


This article will help you to learn make thumbnail image through the system.  To upload images to the server, we need a File Upload control and a button control. Asp.Net simplifies the process of uploading images to the server with the FileUpload control. To start with, place a FileUpload control and a button control on your webpage like as follows:




<div>
<asp:Label ID="labelMessage" runat="server" Text="Browse Image:" ForeColor="navy"Width="220"></asp:Label>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Upload" runat="server" Text="Upload" OnClick="Upload_Click" />
<asp:Button ID="Button1" runat="server" Text="button" onclick="Button1_Click" />
</div>

<div>
<asp:Label ID="label1" runat="server" Text="Normal Image (Full size): " ForeColor="navy" Width="220"></asp:Label>
<asp:Image ID="NormalImage" runat="server" />
</div>

<div>
<asp:Label ID="label2" runat="server" Text="Thumbnail Small Image (50x50)px: " ForeColor="navy" Width="220"></asp:Label>
<asp:Image ID="ThumbnailImageS" runat="server" />
</div>

<div>
<asp:Label ID="label3" runat="server" Text="Thumbnail Large Image (100x100)px: " ForeColor="navy" Width="220"></asp:Label>
<asp:Image ID="ThumbnailImageM" runat="server" />
</div>


In this article I am using the GetThumbnailImage method of the Image class. This method returns the thumbnail image for the given original image. The syntax for this method is-

public Image GetThumbnailImage(int thumbWidth, int thumbHeight, Image.GetThumbnailImageAbort callback, IntPtr callbackData);

Coading




protected void Upload_Click(object sender, EventArgs e)
    {
FileUpload1.SaveAs(MapPath("~/ImageRaja/" + FileUpload1.FileName));
System.Drawing.Image img1 = System.Drawing.Image.FromFile(MapPath("~/imgRaja/") + FileUpload1.FileName);

System.Drawing.Image bmp1 = img1.GetThumbnailImage(50, 50, null, IntPtr.Zero);
bmp1.Save(MapPath("~/thumbnailRaja/S/") + FileUpload1.FileName);
System.Drawing.Image bmp2 = img1.GetThumbnailImage(100, 100, null, IntPtr.Zero);
bmp2.Save(MapPath("~/thumbnailRaja/L/") + FileUpload1.FileName);
NormalImage.ImageUrl = "~/ ImageRaja /" + FileUpload1.FileName;
ThumbnailImageS.ImageUrl = "~/ thumbnailRaja /S/" + FileUpload1.FileName;
ThumbnailImageM.ImageUrl = "~/ thumbnailRaja /L/" + FileUpload1.FileName;
      }
 

No comments:

Post a Comment