By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,954 Members | 1,540 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,954 IT Pros & Developers. It's quick & easy.

Strange happening creating thumbnail...

100+
P: 137
Hello,
I have this program and when i want to load pictures it crashes at the form.showdialog()....???

Here it goes:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub CmbPath_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmbPath.SelectedIndexChanged
  2.  
  3.  
  4.         Dim Table As DataTable
  5.         Dim i As Integer
  6.         Dim ThumbSize As Integer = 160
  7.         Dim ThumbNail As Image = Nothing
  8.  
  9.         FlowLayoutPanel1.Controls.Clear()
  10.  
  11.         Dim SQL As String = "SELECT fotonaam, fotomap, textveld FROM foto WHERE (fotomap = '" & Replace(CmbPath.Text, "'", "''") & "');"
  12.  
  13.         Table = SelectQuery(SQL)
  14.         Dim ThumbPicturearr(Table.Rows.Count) As PictureBox
  15.         Dim TextField(Table.Rows.Count) As TextBox
  16.         Dim FlowPanel(Table.Rows.Count) As FlowLayoutPanel
  17.  
  18.         While Table.Rows.Count <> i
  19.  
  20.             Dim Photo As Image = Image.FromFile((Table.Rows(i).Item("fotomap") & "\" & Table.Rows(i).Item("fotonaam")))
  21.             Try
  22.  
  23.                 'Determine the scale of the imahe
  24.                 Dim Scale As Single = CSng(IIf(Photo.Width > Photo.Height, ThumbSize / Photo.Width, ThumbSize / Photo.Height))
  25.  
  26.                 Dim Width As Integer = CInt(Photo.Width * Scale)
  27.                 Dim Height As Integer = CInt(Photo.Height * Scale)
  28.  
  29.                 ThumbNail = Photo.GetThumbnailImage(Width, Height, Nothing, New IntPtr)
  30.  
  31.             Catch ex As Exception
  32.  
  33.                 MsgBox("Error creating thumbnail:" & vbCr & ex.Message)
  34.  
  35.             End Try
  36.  
  37.             Try
  38.                 ThumbPicturearr(i) = New PictureBox
  39.                 ThumbPicturearr(i).Name = "Foto" & i
  40.                 ThumbPicturearr(i).Height = 130
  41.                 ThumbPicturearr(i).Width = 160
  42.                 ThumbPicturearr(i).BackColor = Color.DarkGray
  43.                 ThumbPicturearr(i).Image = ThumbNail
  44.                 ThumbPicturearr(i).SizeMode = PictureBoxSizeMode.Zoom
  45.                 ThumbPicturearr(i).BorderStyle = BorderStyle.Fixed3D
  46.  
  47.                 TextField(i) = New TextBox
  48.                 TextField(i).BackColor = Color.DarkGray
  49.                 TextField(i).ForeColor = Color.WhiteSmoke
  50.                 TextField(i).Font = New Font("Ms sans serif", 12, FontStyle.Regular, GraphicsUnit.Pixel)
  51.                 TextField(i).Size = New Size(160, 20)
  52.                 TextField(i).TextAlign = HorizontalAlignment.Center
  53.                 TextField(i).Text = Table.Rows(i).Item("textveld")
  54.                 TextField(i).BorderStyle = BorderStyle.FixedSingle
  55.                 TextField(i).Enabled = False
  56.                 TextField(i).Location = New Point(ThumbPicturearr(i).Location.X - 10, ThumbPicturearr(i).Location.Y + 5)
  57.  
  58.                 FlowPanel(i) = New FlowLayoutPanel
  59.                 FlowPanel(i).Size = New Size(170, 170)
  60.                 FlowPanel(i).BackColor = Color.DarkGray
  61.                 FlowPanel(i).FlowDirection = FlowDirection.TopDown
  62.  
  63.                 FlowPanel(i).Controls.Add(ThumbPicturearr(i))
  64.                 FlowPanel(i).Controls.Add(TextField(i))
  65.  
  66.                 FlowLayoutPanel1.Controls.Add(FlowPanel(i))
  67.  
  68.                 ThumbNail.Dispose()
  69.  
  70.                 'Increase the counter
  71.                 i = i + 1
  72.  
  73.             Catch ThumbError As Exception
  74.  
  75.                 MsgBox("Error creating thumbnails for pictureboxes:" & vbCr & ThumbError.Message)
  76.  
  77.             End Try
  78.  
  79.         End While
  80.  
  81.         Table.Dispose()
  82.  
  83.  
  84.     End Sub
  85.  
  86. ' AND THEN HERE IT CRASHES AFTER I CALLED THE FORM YOU"LL SEE A PART OF IT UP HERE
  87.  
  88.  Dim EditPhoto As New Bewerk
  89.  
  90.         EditPhoto.ShowDialog()
  91.  
  92.  
At editPhoto.ShowDialog() i get the error: Parameter is not valid.
Strange, because the form has already been loaded....

Anybody an idea?

ohyeah, when i replace "ThumbPicturearr(i).Image = ThumbNail" with "ThumbPicturearr(i).Image = Image.FromFile("c:\" & Table.rows(i).Item("fotonaam")" it's working but i don't want him to make al kind of little pictures but directly add the thumbs to the pictureboxes...

Thanks in advance!

Paul
Aug 27 '08 #1
Share this Question
Share on Google+
2 Replies


Plater
Expert 5K+
P: 7,872
Which line does the error actually say it is occuring on? It shouldn't be on the ShowDialog() call, unless that form was already loaded and visible maybe?

Also, when you call .Dispose() on the iamge, it disposes all references to it.
So you would need to change this:
ThumbPicturearr(i).Image = ThumbNail
to this:
ThumbPicturearr(i).Image = ThumbNail.Clone()

If you want to call .Dispose() on the image.
Aug 27 '08 #2

100+
P: 137
Hmm, Why are some answers so simpel, as the question looks very difficult???

That worked perfect!
Just added .clone beheind there an that was it!

Thanks!

(p.s. i like this forum, it's great!)

Regards, Paul
Aug 27 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.