473,796 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange happening creating thumbnail...

137 New Member
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.ShowD ialog() i get the error: Parameter is not valid.
Strange, because the form has already been loaded....

Anybody an idea?

ohyeah, when i replace "ThumbPicturear r(i).Image = ThumbNail" with "ThumbPicturear r(i).Image = Image.FromFile( "c:\" & Table.rows(i).I tem("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 1551
Plater
7,872 Recognized Expert Expert
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 New Member
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
3747
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 machines. The code opens MS Word through Automation and then opens a particular Word doc. It's still working fine on most machines; but on one or two of them, the user is getting an Automation Error. The code used is as follows: Dim objWord As...
1
2616
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 thumbnails also which again seems very slow. There is a memory bitmap but i can't seem to find any good information about it. I want to be able to create a 32bpp bitmap as fast as possible and also try to make a thumbnail as fast as possible too....
1
1501
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 use to create the thumbnail image...... *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
2
1928
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 store created thumbnail in to hard disk <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %> <%@ Import Namespace="System.Drawing.Imaging"%>
0
9531
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10237
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10187
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10018
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7553
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6795
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.