473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Strange happening creating thumbnail...

137 100+
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
2 1508
Plater
7,872 Expert 4TB
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
djpaul
137 100+
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

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

Similar topics

25
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's...
1
by: James Dean | last post by:
In my program i create a 32ARGB bitmap. To actually create the bitmap seems very slow. In fairness the file size is very big. I support multiple bitmaps as well. I have to convert these bitmaps to...
1
by: James Dean | last post by:
I have thought about creating a thumbnail from my full image but its too slow. What is the best algorithm to use for creating a thumbnail directly from data by yourself. What algorithm do microsoft...
2
by: asad | last post by:
Hello friends, how ru all, i have some problem about saving created thumbnail, following is the code i use for creating thumbnail but thumbnail was not saved it is on memory which method is used to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.