Hello Friends,
Now a days in any web appication comman request made by clients is the generates a thumbnail for any product image or user profile image so here is the solution for the generates thumbnail on fly when admin or user add any image.
Private Function GetThumbnailView(ByVal originalImagePath As String, ByVal height As Integer, ByVal width As Integer) As String
‘Consider Image is stored at path like “ProductImage\\Product1.jpg”
‘Now we have created one another folder ProductThumbnail to store thumbnail image of product.
‘So let name of image be same, just change the FolderName while storing image.
Dim thumbnailImagePath As String = originalImagePath.Replace(”ProductImage”, “ProductThumbnail”)
‘If thumbnail Image is not available, generate it.
If Not System.IO.File.Exists(Server.MapPath(thumbnailImagePath)) Then
Dim imThumbnailImage As System.Drawing.Image
Dim OriginalImage As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(originalImagePath))
imThumbnailImage = OriginalImage.GetThumbnailImage(width, height, New System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero)
imThumbnailImage.Save(Server.MapPath(thumbnailImagePath), System.Drawing.Imaging.ImageFormat.Jpeg)
imThumbnailImage.Dispose()
OriginalImage.Dispose()
End If
Return thumbnailImagePath
End Function
Public Function ThumbnailCallback() As Boolean
Return False
End Function
Call this function like
GetThumbnailView(”ProductImage\Product1.jpg”, 100, 100)
Enjoy Friends.
Tags: Create thumbnail for image on fly, Create thumbnail for image on Run Time, Generate thumbnail for image on fly, Generate thumbnail for image on Run time
Hello ! I am Arjun Jadeja a Software Engineer by Profession. You can contribute and I will distribute your ideas through this site. Thanks and Enjoy
Leave a reply