Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

I just dont get it :S


  • Please log in to reply
6 replies to this topic

#1 Wolfy87

Wolfy87

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:18 PM

Posted 04 March 2009 - 01:18 PM

Here is my code:

Public Class Form1

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Dim Image1 As New Bitmap(410, 165)
		Dim x As Integer = 1
		Dim y As Integer = 1
		Image1 = PictureBox1.Image
		PictureBox1.Image = Image1
		For y = y To 165
			For x = x To 410
				If Image1.GetPixel(x, y) = Color.Black Then
					MsgBox("Black found at: " + x.ToString + ", " + y.ToString)
				End If
			Next x
		Next y
	End Sub
End Class

But i keep getting this error: Parameter must be positive and < Width. Parameter name: x

I just dont see whats wrong with it :S this has happend befour, i do not see any logical reason.

Thanks for any help, Wolfy87.

BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:03:18 PM

Posted 04 March 2009 - 04:06 PM

Hello :thumbsup:

2 things... on which line does the error occur, and does it occur at runtime or compile time?

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:18 PM

Posted 05 March 2009 - 12:32 PM

It is on run time so i guess i have got my arrays wrong ie it <= 0 etc and it occors here

If Image1.GetPixel(x, y) = Color.Black Then

I have had trouble with get pixel befour, and i think its still playing up =/

Thanks Billy, Wolfy87.

#4 jpshortstuff

jpshortstuff

    WhatTheTech Teacher


  • Members
  • 660 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:UK
  • Local time:11:18 PM

Posted 05 March 2009 - 02:28 PM

I'm no VB programmer but I think I can see a problem.

Dim Image1 As New Bitmap(410, 165)
...
...
For y = y To 165
For x = x To 410


When programming, we count from 0. Therefore, when you defined your Image to have a width of 410 (indicated in blue) - you are giving it indexes from 0-409. So, when you use x from 1-410, the last index is too large. The same goes for your y variable.

Hope that helps.
Trained at the What The Tech Classroom where you too could learn to help others.

My help is free, however, if you wish to make a small donation to show appreciation and to help me continue the fight against Malware, then click here Posted Image

Posted Image

#5 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:03:18 PM

Posted 05 March 2009 - 03:16 PM

JP -- Visual Basic generally uses one-indexed arrays (confusing, I know).

Wolfy: Jp is correct -- even though Visual Basic usually indexes things at 1, the Bitmap.GetPixel method does not. See here:
http://msdn.microsoft.com/en-us/library/sy...p.getpixel.aspx


ArgumentOutOfRangeException-

x is less than 0, or greater than or equal to Width.
or
y is less than 0, or greater than or equal to Height


Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#6 jpshortstuff

jpshortstuff

    WhatTheTech Teacher


  • Members
  • 660 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:UK
  • Local time:11:18 PM

Posted 05 March 2009 - 03:26 PM

That's good to know I guess - silly VB :thumbsup:

Even sillier that its not consistent though...

Ah well.
Trained at the What The Tech Classroom where you too could learn to help others.

My help is free, however, if you wish to make a small donation to show appreciation and to help me continue the fight against Malware, then click here Posted Image

Posted Image

#7 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:03:18 PM

Posted 05 March 2009 - 03:29 PM

System.Drawing.Bitmap was probably written in C#... therefore some of the kludges that make VB work in the .NET framework lead to these inconsistencies. For example, if you look at an array inside of VB, you'll see index 0 of the array filled with ".NET Visual Basic Array Pseudo Element" . When VB was finalized, they wanted to make the arrays zero indexed like the rest of the .NET languages. However, they realized this would be a bad idea because they wanted to allow easy porting of VB6 code :thumbsup:

Hence the apparent inconsistency... C# has zero indexed (sane) arrays ;)

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users