Tuesday, January 26, 2010

how to create thumbnail image

 Create thumbnail.aspx Page


<%@ Import Namespace=System.Drawing %>
<%@ Import Namespace=System %>
<%@ Import Namespace=System.Web %>
<html>
<script language="VB" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
' Initialize objects
Dim objImage, objThumbnail As System.Drawing.Image
Dim strServerPath, strFilename As String
Dim shtWidth, shtHeight As Short    
Dim PRTarget, PROriginal As Short
' Get image folder path on server - use "\" string if root
' strServerPath = Server.MapPath("images\")
' Retrieve name of file to resize from query string
' strFilename = strServerPath & Request.QueryString("filename")
strFilename = Request.QueryString("FileName")
' Retrieve file, or error.gif if not available
Try
    objImage = objImage.FromFile(Server.MapPath(strFilename))
Catch
    objImage = objImage.FromFile(Server.MapPath("images/default.gif"))
End Try
' Retrieve width from query string
If Request.QueryString("width") = Nothing Then
    shtWidth = objImage.Width
ElseIf Request.QueryString("width") < 1 Then
    shtWidth = 100
Else
    shtWidth = Request.QueryString("width")
End If
If Request.QueryString("height") = Nothing Then
    shtHeight = objImage.Height
ElseIf Request.QueryString("height") < 1 Then
    shtHeight = 100
Else
    shtHeight = Request.QueryString("height")
End If
PROriginal = objImage.Width / objImage.Height
PRTarget = shtWidth / shtHeight
if objImage.Width > objImage.Height Then
    ' Work out a proportionate height from width
    shtHeight = objImage.Height / (objImage.Width / shtWidth)
Else
    ' Work out a proportionate width from height
    shtWidth = objImage.Width / (objImage.Height / shtHeight)
End If
' Create thumbnail
If objImage.Width<=shtWidth And objImage.Height<=shtHeight Then
    objThumbnail = objImage
Else
            objThumbnail = objImage.GetThumbnailImage(shtWidth, _
            shtHeight, Nothing, System.IntPtr.Zero)
End If
' Send down to client
Response.ContentType = "image/jpeg"
objThumbnail.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg)
' Tidy up
objImage.Dispose()
objThumbnail.Dispose()
End Sub
</script>
</html>

Action Method in Mvc

In this section, you will learn about the action method of controller class. All the public methods of a Controller class are called Act...