How to use Asp.net
  • Home
  • About us
  • Disclaimer
  • joy of helping
KEEP IN TOUCH

How to create thumbnail of images in asp.net vb.net

Mar27
2011
Leave a Comment Written by vikram

In this article I have created thumbnails from large images using coding. This code will help how to make thumbnail images before to upload on the server You can specify the size like height and width of the thumbnail images.

you can save thumbnail images in thumbnail folder and if you need to display the full image after click on the thubnail then you can save full image in image folder..

its all about your logic and what you wants to do.

hope it will help you…

( i have coded in c# too)

 

Imports System.IO

Imports System.Drawing

Imports System.Drawing.Image

Imports System.Drawing.Imaging

Partial Class Default2

Inherits System.Web.UI.Page

Public Function ThumbnailCallback() As Boolean

Return (False)

End Function

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

If img_upload.PostedFile.ContentLength > 0 Then

Dim UploadedFileName As String

UploadedFileName = img_upload.PostedFile.FileName

img_upload.PostedFile.SaveAs(Request.PhysicalApplicationPath & “images/” & UploadedFileName)

 

Dim size As Image = Image.FromFile(Request.PhysicalApplicationPath & “images/” & UploadedFileName)

 

Dim h As Int32 = size.Height

Dim w As Int32 = size.Width

 

‘ You can check the size of the image after upload on the server if that file according to yur dimension then it will submit and will create the thumbnail of the images other wise it will delete from the server.

If (w >= 300 And w <= 1024) And (h >= 30 And h <= 768) Then Label1.Text = “Submit” Else Label1.Text = “Error” size.Dispose() ‘ the image is not in actual range of size then delete it from images folder File.Delete(Server.MapPath(“images”) + “/” + UploadedFileName) Exit Sub End If Try ‘Read in the image filename whose thumbnail has to be created Dim imageurl As String = UploadedFileName ‘Read in the width and height Dim height As Int32 = 175 Dim width As Int32 = 180 If (imageurl.IndexOf(“/”) >= 0) Or (imageurl.IndexOf(“\\”) > 0) Then

Response.End()

End If

imageurl = “images\” + imageurl

Dim fullSizeImg As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(imageurl))

Dim dummyCallBack As New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback) ‘Delegate will call the method ThumbnailCallback

Dim thumbNailImg As System.Drawing.Image = fullSizeImg.GetThumbnailImage(width, height, dummyCallBack, IntPtr.Zero)

‘We need to create a unique filename for each generated image

Dim MyDate As DateTime = DateTime.Now

Dim MyString As String = UploadedFileName

‘Save the thumbnail in Png format. You may change it to a diff format with the ImageFormat property

thumbNailImg.Save((Request.PhysicalApplicationPath & “Thumb_images\”) + MyString, ImageFormat.Jpeg) ‘ for imageformat add ”Imports System.Drawing.Imaging

thumbNailImg.Dispose()

Catch ex As Exception

Label.text =”error message”

End Try

Else

End If

End Sub

End Class

 

 

With Regards

Vik

Posted in Asp.net
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
« How to send E-mail in Asp.net Vb.net
» How to create thumbnail of images in asp.net C#.net

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Joy of Helping

Any sort of help to the children who are fatherless, poor & are from far-off areas.
Joy of Helping

Facebook Link

Asp dot Net ,Ajax,Xml.

Recent Posts

  • ROW_NUMBER(), NTILE(), partition by, Duplicate Records, CTE sql server 2008
  • How to get second highest Salary sql server 2008
  • Insert values, insert into, insert default value, insert execute and select into sql server 2008
  • How to Bind GridView with SqlDataReader in Asp.net
  • how to attach files to email without storing on disk using Asp.net FileUpload control

Recent Comments

  • Anonymous on ROW_NUMBER(), NTILE(), partition by, Duplicate Records, CTE sql server 2008
  • dhananjay on How to use GridView with Insert, Edit, Update, Delete the Ado.net way C#
  • dev on How can we limit the characters in multiline textbox asp.net using JavaScript
  • navneet on How to display image in Image control after upload on the server asp.net C#
  • AnhVu on How to do Shopping Cart in Asp.net C#

Archives

  • February 2013
  • September 2012
  • April 2012
  • January 2012
  • October 2011
  • August 2011
  • May 2011
  • April 2011
  • March 2011

Categories

  • Asp.net
  • jQuery
  • Sql Server

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

EvoLve theme by Theme4Press  •  Powered by WordPress How to use Asp.net