I am new in this forum. I have one problem with my Vb.net example. I want to create thumbnails dynamically in Vb.net .how it is possible. Please give me step by step code which easy to understand me. Your help highly appericated.
I am new in this forum. I have one problem with my Vb.net example. I want to create thumbnails dynamically in Vb.net .how it is possible. Please give me step by step code which easy to understand me. Your help highly appericated.
I suggest you to refer following example, which will give you something idea about the use code to Create thumbnails dynamically:
Code:Function CreateThumbnail(ByVal inSourceFile As String, ByVal inDestinationFile As String, ByVal ThumbWidth As Integer, ByVal ThumbHeight As Integer) As Boolean Dim imageFile As System.Drawing.Image Dim outputFstream As New FileStream(inSourceFile, FileMode.Open, FileAccess.Read) Dim ImageAbortCallBack As System.Drawing.Image.GetThumbnailImageAbort imageFile = System.Drawing.Image.FromStream(outputFstream) ImageAbortCallBack = New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ImageAbortDummyCallback) imageFile = imageFile.GetThumbnailImage(ThumbWidth, ThumbHeight, ImageAbortCallBack, IntPtr.Zero) 'IntPtr = A platform-specific type that is used to represent a pointer or a handle. imageFile.Save(inDestinationFile, System.Drawing.Imaging.ImageFormat.Jpeg) outputFstream.Close() outputFstream = Nothing imageFile = Nothing End Function
Try this,
Code:Private Sub btnOpen_Click(ByVal sender As Object, ByVal e As EventArgs) If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then txtFileNm.Text = openFileDialog1.FileName End If End Sub Private Sub btnOpen_Click(ByVal sender As Object, ByVal e As EventArgs) If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then txtFileNm.Text = openFileDialog1.FileName End If End Sub Dim imgThumb As Image = Nothing Private Sub btnGenerateThumbnail_Click(ByVal sender As Object, ByVal e As EventArgs) Try Dim image As Image = Nothing ' Check if textbox has a value If txtFileNm.Text <> String.Empty Then image = Image.FromFile(txtFileNm.Text) End If ' Check if image exists If Not image Is Nothing Then imgThumb = image.GetThumbnailImage(100, 100, Nothing, New IntPtr()) Me.Refresh() End If Catch MessageBox.Show("An error occured") End Try End Sub Private Sub Form1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) If Not imgThumb Is Nothing Then e.Graphics.DrawImage(imgThumb,30, 20, imgThumb.Width, imgThumb.Height) End If End Sub
Bookmarks