Code to make a Thumbnail image in

Code to make a Thumbnail image


This code is use to make a thumbnail of an image. generally,
it is use when we have to give the facility to upload images in applications folder. then
it have to create thumbnail first...

You have to add below code in seperate page which will access by main page with
file name consist in query string.

eg. "webform1.aspx?file=filename.jpg"

NOTE: you have to sent filename with QueryString.

Add Namespaces

Imports System
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Imaging

Add below code on page load


' get the file name -- fall800.jpg
Dim file As String = Request.QueryString("file")

file = Server.MapPath("headshotsThumbs") + "\" & file
' create an image object, using the filename we just retrieved
Dim image As System.Drawing.Image = System.Drawing.Image.FromFile(file)

' create the actual thumbnail image
Dim thumbnailImage As System.Drawing.Image = New Bitmap(Server.MapPath(Request.ApplicationPath) & "\headshotsThumbs\" &


' make a memory stream to work with the image bytes
Dim imageStream As New MemoryStream()

' put the image into the memory stream
thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg)

' make byte array the same size as the image
Dim imageContent As Byte() = New Byte(imageStream.Length - 1) {}

' rewind the memory stream
imageStream.Position = 0

' load the byte array with the image
imageStream.Read(imageContent, 0, CInt(imageStream.Length))
' return byte array to caller with image type
Response.ContentType = "image/jpeg"
Catch ex As Exception
Dim [error] As String = ""
[error] = ex.Message.ToString()

End Try

It will find the perticular image and will create thumbnail.

Nilesh Jadhav


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: