|
-
Apr 29th, 2012, 01:13 PM
#1
Thread Starter
Addicted Member
Fastest way to generate thumbnails.
Hello,
I'm looking for suggestions on the fastest way to generate thumbnails using VB.net and multiple computers without bogging down the UI.
Right now I have 3 computers and I run an instance of my thumbnail generator code on each. One computer hosts the images. The other two computers access the folder of images via the network.
My code is written to compare the main folder and a thumbnail folder to see if new thumbnails need to be generated. If so, a thread is generated and the thumbnail generation code is ran on the thread. There are 5 threads created in all. So, theoretically, across 3 machines, I'm getting 5 independent threads and I'm thinking that Windows 7 automatically spreads the load across the local cores. In an effort to avoid duplicating work, the comparison is done before the generation of each thumbnail.
This method is faster than using only one computer but drags down the performance on all computers (THE UI also becomes unresponsive). I'm looking for a better way to 1.) Produce the thumbnails as fast as possible 2.) Keep all UI's responsive (boy possibly controlling the priority setting) and 3.) Done within a single instance of the program.
In the #3, I mentioned that I would like to use one instance. Is it possible for networking information be used by the hosting computer that will allow threads to run on the other 2 computers? This way, the 15 threads will be controlled by a single host computer.
Here is a snippet of my code:
Code:
Public Sub CreateThumbsFUNCTION(ByVal IMAGE As String, ByVal MAXDIMENSION As Integer)
'following code resizes picture to fit.
'IMAGE needs the full path
'If thumbnail already exists, it will skip
Dim newimage As System.Drawing.Image
Dim EW As New ExifWorks(IMAGE)
Dim OUTPUTPATH As String() = ExtractPath(IMAGE) ' Note, the '\' is returned
Dim NewOutputPath As String = OUTPUTPATH(0) & "thumbs_MIS\"
If File.Exists(NewOutputPath & OUTPUTPATH(1)) Then
' do nothing
Else
Dim CreateFlagg As Integer = 1
Dim Hout, Wout As Integer
newimage = Rotate_Image_From_EXIF(IMAGE)
Dim bm As New Bitmap(newimage)
If bm.Height < MAXDIMENSION And bm.Width < MAXDIMENSION Then
Hout = bm.Height
Wout = bm.Width
Else
If bm.Height > bm.Width Then
Hout = MAXDIMENSION
Wout = Hout * (bm.Width / bm.Height)
Else
Wout = MAXDIMENSION
Hout = Wout * (bm.Height / bm.Width)
End If
End If
Dim thumb As New Bitmap(Wout, Hout) ' New object for smaller image
Dim g As Graphics = Graphics.FromImage(thumb)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(bm, New Rectangle(0, 0, Wout, Hout), New Rectangle(0, 0, bm.Width, _
bm.Height), GraphicsUnit.Pixel)
g.Dispose()
'MsgBox(Directory.Exists(NewOutputPath))
If Directory.Exists(NewOutputPath) = False Then
Directory.CreateDirectory(NewOutputPath)
End If
'MsgBox(NewOutputPath & OUTPUTPATH(1))
Try
thumb.Save(NewOutputPath & OUTPUTPATH(1), System.Drawing.Imaging.ImageFormat.Jpeg) 'can use any image format
bm.Dispose()
thumb.Dispose()
newimage.Dispose()
EW.Dispose()
Catch ex As Exception
msgbox(ex.text)
End Try
End If
End Sub
Thanks,
Adrian
Last edited by adrian1906; Apr 29th, 2012 at 05:21 PM.
Reason: Typo.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|