Advertisement

04.23.2008 at 03:41AM PDT, ID: 23345965
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

How to delete an image file, after being referenced by imagelist

Tags: VB.net
Hi experts,

I've got a program that loads images on the drive, into an imagelist, and displays them onscreen.

Now I want to loop through the files at a later stage on the hdd, and move them to another directory, but i can't. VB.net is giving me the error that the file is in use by another process.
I thought the image list contains the images self? Seems like it's a reference to the images or something???

How can this be done?
Code below:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
Private Sub cmdViewImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdViewImage.Click
 
		Dim v_StockID As Integer
		'Dim v_strUploadDir As String
		'Dim v_ImageLocations() As String
		Dim v_Path As String
		Dim v_ImageResizer As New clsImageResizer
		Dim v_Image As Image
		Dim v_Counter As Integer
 
		Dim v_Connection As New SqlClient.SqlConnection
		Dim v_Command As New SqlClient.SqlCommand
		Dim v_RecordSet As SqlClient.SqlDataReader
 
		Try
 
			Cursor = Cursors.WaitCursor
 
			g_ImageList.Clear()
			dilLoader.Controls.Clear()
 
			If txtImgStockID.Text <> "" Then
 
				v_Counter = 0
				v_StockID = txtImgStockID.Text
				v_Path = My.Settings.ProductImgUploadDir & v_StockID & "\"
 
				v_Connection.ConnectionString = My.Settings.ConnString
 
				v_Command.Connection = v_Connection
				v_Command.CommandType = CommandType.StoredProcedure
				v_Command.CommandText = "proc_MFM_Get_Stock_Image_Directories"
				v_Command.Parameters.Add("@StockID", SqlDbType.Int)
				v_Command.Parameters.Item("@StockID").Value = v_StockID
 
				OpenConnection(v_Connection)
 
				v_RecordSet = v_Command.ExecuteReader
 
				While v_RecordSet.Read
					If IO.File.Exists(v_Path & v_RecordSet("PictureLarge")) Then
 
						v_Image = Image.FromFile(v_Path & v_RecordSet("PictureLarge"))
						v_Image.Tag = v_Path & v_RecordSet("PictureLarge")
 
						g_ImageList.Add(v_Image.Clone)
						g_ImageList.Item(v_Counter).Tag = v_Path & v_RecordSet("PictureLarge")
						v_Image.Dispose()
						v_Counter = v_Counter + 1
 
					End If
				End While
 
				If g_ImageList.Count > 0 Then
					AddImages(g_ImageList, g_ThumbnailImgSize)
				End If
			End If
 
		Catch ex As Exception
			MsgBox(ex.Message, MsgBoxStyle.Critical, "cmdViewImage_Click")
		Finally
			v_Image = Nothing
			v_ImageResizer = Nothing
			CloseConnection(v_Connection)
			Cursor = Cursors.Default
			GC.Collect()
		End Try
	End Sub
 
 
 
' AddImages Sub
	Sub AddImages(ByRef g_ImageList As List(Of Image), ByVal v_ImageDisplaySize As Size)
 
		Dim v_PanelWidth As Double, v_SpacerWidth As Double
		Dim v_ImageCountPerLine As Integer
		Dim v_Comp As PictureBox
		Dim v_Checkbox As CheckBox
		Dim i As Integer, j As Integer
		Dim v_Xpos, v_Ypos As Integer
		Dim img As New clsImageResizer()
 
		Try
 
			i = 0
			j = 1
			v_Xpos = 0
			v_Ypos = 5
 
			dilLoader.Controls.Clear()
			If g_ImageList.Count > 0 Then
 
				' Get the full "workable" width of the component (-scrollbar width)
				v_PanelWidth = dilLoader.Width - 17
 
				v_ImageCountPerLine = Math.Floor((v_PanelWidth) / (v_ImageDisplaySize.Width))	' 3
				v_SpacerWidth = (v_PanelWidth) - (v_ImageCountPerLine * v_ImageDisplaySize.Width)	'69
				v_SpacerWidth = Math.Floor(v_SpacerWidth / (v_ImageCountPerLine + 1))
 
				While i < g_ImageList.Count
 
					img.LoadImage(g_ImageList.Item(i))
 
					v_Comp = New PictureBox
					v_Comp.Name = "pbImage"
					v_Comp.Tag = i
					v_Comp.BorderStyle = BorderStyle.FixedSingle
					v_Comp.SizeMode = PictureBoxSizeMode.CenterImage
					v_Comp.Parent = dilLoader
					v_Comp.MaximumSize = v_ImageDisplaySize	'New Size(v_ImageDisplaySize, v_ImageDisplaySize)
					v_Comp.Size = v_ImageDisplaySize 'New Size(v_ImageDisplaySize, v_ImageDisplaySize)
					v_Comp.Image = img.GetImage(v_ImageDisplaySize).Clone
 
					AddHandler v_Comp.MouseUp, AddressOf v_Comp_MouseUp
 
					v_Xpos = v_Xpos + v_SpacerWidth
					v_Comp.Location = New Drawing.Point((v_Xpos), v_Ypos)
 
					v_Checkbox = New CheckBox
					v_Checkbox.Parent = dilLoader
					v_Checkbox.Name = "cbImage"
					v_Checkbox.Tag = i
					v_Checkbox.FlatStyle = FlatStyle.Flat
					v_Checkbox.Text = ""
					v_Checkbox.Visible = True
					v_Checkbox.Size = New Size(11, 11)
					v_Checkbox.MaximumSize = New Size(11, 11)
					v_Checkbox.Location = New Drawing.Point(v_Comp.Left, v_Comp.Top)
					v_Checkbox.BringToFront()
 
					' Update the locations here:
					If j = v_ImageCountPerLine Then
						j = 0
						v_Xpos = 0
						v_Ypos = v_Ypos + v_ImageDisplaySize.Height + 25
					Else
						v_Xpos = v_Xpos + v_ImageDisplaySize.Width
					End If
 
					v_Comp = Nothing
					v_Checkbox = Nothing
					i = i + 1
					j = j + 1
 
				End While
 
			End If
 
		Catch ex As Exception
			MsgBox(ex.Message, MsgBoxStyle.Critical, "AddImages")
		End Try
	End Sub
 
 
 
 
' To move the images: 
	Private Sub MoveImageFiles(ByVal v_StockID As Integer)
 
		Dim v_tempStrDir As String
		Dim v_tempDir As DirectoryInfo
		Dim v_tempOriginalDir As DirectoryInfo
		Dim v_File As FileInfo
 
		Try
 
			' old_22_apr_2008_09_37_22
			v_tempStrDir = "old_" & Format(Now.Day, "00") & "_" & MonthName(Now.Month, True) & "_" & Now.Year & "_" & Format(Now.Hour, "00") & "_" & Format(Now.Minute, "00") & "_" & Format(Now.Second, "00")
			v_tempStrDir = My.Settings.ProductImgUploadDir & v_StockID & "\" & v_tempStrDir
 
			IO.Directory.CreateDirectory(v_tempStrDir)
 
			v_tempDir = New DirectoryInfo(v_tempStrDir)
			v_tempOriginalDir = New DirectoryInfo(My.Settings.ProductImgUploadDir & v_StockID)
			For Each v_File In (v_tempOriginalDir.GetFiles())
 
				v_File.MoveTo(Path.Combine(v_tempDir.FullName, v_File.Name))
 
			Next
 
			v_tempDir = Nothing
			v_tempOriginalDir = Nothing
			v_File = Nothing
 
		Catch ex As Exception
			MsgBox(ex.Message, MsgBoxStyle.Critical, "MoveImageFiles")
		Finally
			GC.Collect()
		End Try
	End Sub
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: Kobz46
Solution Provided By: Idle_Mind
Participating Experts: 2
Solution Grade: A
Views: 5
Translate:
Loading Advertisement...
04.23.2008 at 05:09AM PDT, ID: 21419688

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.23.2008 at 05:44AM PDT, ID: 21419980

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.23.2008 at 08:40AM PDT, ID: 21421908

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.23.2008 at 12:15PM PDT, ID: 21424253

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 04:10AM PDT, ID: 21523718

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 07:30AM PDT, ID: 21525038

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 05:11PM PDT, ID: 21578918

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 11:07PM PDT, ID: 21580338

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • Automotive
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Displays / Monitors
  • Handhelds / PDAs
  • Components
  • Peripherals
  • Laptops/Notebooks
  • Servers
  • Misc
  • Apple
  • Embedded Hardware
  • Networking Hardware
  • Storage
  • Desktops
  • New Users
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMware
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Virtualization
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • Web Computing
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Consulting
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMware
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Automation
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Web Services
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Web Computing
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Lounge
  • Business Travel
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
  • Automotive
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
04.23.2008 at 05:09AM PDT, ID: 21419688

Rank: Master

Hello,
Try to load image to the ImageList in a different way using FileStream, instead of directly making a Image from the path. Following snippet may help you. Use img to add in the ImageList. Then try deleting, should delete.

       
1:
2:
3:
4:
5:
Dim img As Bitmap
       Dim fs As IO.FileStream
        fs = New IO.FileStream("PATH", IO.FileMode.Open, IO.FileAccess.Read)
        img = New Bitmap(fs)
        fs.Close()
Open in New Window
 
04.23.2008 at 05:44AM PDT, ID: 21419980
Hi  r,

Thank you for the quick response!

I've tried this, but when I call the method " MyImage.GetThumbnailImage(1, 1, Nothing, IntPtr.Zero) " on that image, it gives me an "Out of memory" error.

Also, where I'm creating the images - when i've created the image through stream, a GDI+ error occures in the PropertyIDList and PropertyItems properties of the image. Don't know whether this has something to do with it?
Both these errors don't occur when just using a plain image... (image.fromfile())

Am I doing something wrong somewhere?
 
04.23.2008 at 08:40AM PDT, ID: 21421908

Rank: Genius

Does this give an error?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
While v_RecordSet.Read
    If IO.File.Exists(v_Path & v_RecordSet("PictureLarge")) Then
        Dim img As Image = Image.FromFile(v_Path & v_RecordSet("PictureLarge"))
        v_Image = New Bitmap(img)
        img.Dispose()
        v_Image.Tag = v_Path & v_RecordSet("PictureLarge")
        g_ImageList.Add(v_Image)
        g_ImageList.Item(v_Counter).Tag = v_Path & v_RecordSet("PictureLarge")
        v_Counter = v_Counter + 1
    End If
End While
Open in New Window
Accepted Solution
 
04.23.2008 at 12:15PM PDT, ID: 21424253
Hi!

The previous snippet didn't give an error, and worked 100%, but isn't there any way that i can stick to the image object instead of bitmap?
I'm using a function to check for duplicate images, and since i've used bitmap in the function above, the hash checking is obviously not working anymore... ?

I understand this is a smaller seperate part, so i'll up the points for this one...
Is there a way that i can compare the 2 images, to see if they're alike?

Below is what i've got currently, but it isn't working anymore...
Isn't there something universal to check all image formats on something?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
Function ImagesSimilar(ByRef image1 As Image, ByRef image2 As Image) As Boolean
		Try
			ImagesSimilar = True
 
			If image1.Size <> image2.Size Then ' difference
				ImagesSimilar = False
				'ElseIf (My.Computer.FileSystem.GetFileInfo(image1.Tag).Length <> My.Computer.FileSystem.GetFileInfo(image2.Tag).Length) Then
				'	ImagesSimilar = False
			Else
				Dim v_Converter As New System.Drawing.ImageConverter
				Dim v_SHA256Managed As New System.Security.Cryptography.SHA256Managed
 
				Dim btImage1(1) As Byte
				Dim btImage2(1) As Byte
 
				Dim i As Integer
				i = 0
 
				btImage1 = v_Converter.ConvertTo(image1, btImage1.GetType())
				btImage2 = v_Converter.ConvertTo(image2, btImage2.GetType())
 
				Dim hash1() As Byte
				Dim hash2() As Byte
				hash1 = v_SHA256Managed.ComputeHash(btImage1)
				hash2 = v_SHA256Managed.ComputeHash(btImage2)
 
				While ((i < (hash1.Length / 2)) And (i < (hash2.Length / 2)))
					If hash1(i) <> hash2(i) Then
						ImagesSimilar = False
						Exit While
					End If
					i = i + 1
				End While
 
				v_Converter = Nothing
				v_SHA256Managed = Nothing
				btImage1 = Nothing
				btImage2 = Nothing
				hash1 = Nothing
				hash2 = Nothing
 
			End If
 
		Catch ex As Exception
			MsgBox(ex.Message, MsgBoxStyle.Critical, "ImagesSimilar")
		Finally
			GC.Collect()
		End Try
	End Function
Open in New Window
 
05.08.2008 at 04:10AM PDT, ID: 21523718
Hi Idle_Mind!

Your previous answer was correct, and it's working now, but by getting THAT right, my function that compares the 2 images broke, as i assume the 1 is now a bitmap object, and the other one is an image object. I tried converting the bitmap to an image, but that doesn't help. I'm upping the points to 500, where you will get 300 for that answer, and the remaining 200 for helping me out on the comparison issue... ?
 
05.08.2008 at 07:30AM PDT, ID: 21525038

Rank: Genius

I'll take a looksee...
 
05.15.2008 at 05:11PM PDT, ID: 21578918

Rank: Genius

"I tried converting the bitmap to an image, but that doesn't help."

How about the other direction then?

It ~seems~ to work for me when I convert both images to a bitmap instead:
*** NOTICE THAT I CHANGED BOTH PARAMETERS TO "BYVAL" INSTEAD OF "BYREF" ***
1:
2:
3:
4:
5:
6:
     Function ImagesSimilar(ByVal image1 As Image, ByVal image2 As Image) As Boolean
        image1 = New Bitmap(image1)
        image2 = New Bitmap(image2)
        Try
            ImagesSimilar = True
            ...
Open in New Window
Assisted Solution
 
05.15.2008 at 11:07PM PDT, ID: 21580338
Hi IM! That Worked yes! :-) It uses a little bit more memory when adding images now, but they're not gonna add 100 images at once - maybe 10 per product at MOST. So that's no trainsmash... :-)

Thanx a mil for the help! Once again...

K
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628