parameter must be positive and < height

Joined
Nov 4, 2019
Messages
6
Programming Experience
1-3
VB.NET:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim bmp1 As Bitmap = Image.FromFile("C:\Temp\ImageCompare\chill.jpg")
        Dim bmp2 As Bitmap = Image.FromFile("C:\Temp\ImageCompare\chill1.jpg")

        Dim sameCount As Integer = 0
        Dim diffCount As Integer = 0

        For x As Integer = 0 To (bmp1.Width) - 1
            For y As Integer = 0 To (bmp1.Height) - 1
                If bmp1.GetPixel(x, y).Equals(bmp2.GetPixel(x, y)) Then
                    sameCount += 1
                Else
                    diffCount += 1
                End If
            Next
        Next

        Dim total As Integer = sameCount + diffCount

        MessageBox.Show(String.Format("Same Percentage: {0}{1}Difference Percentage: {2}", _
                                      (sameCount / total).ToString("p"), Environment.NewLine, (diffCount / total).ToString("p")))
    End Sub

While running this code issues in some image.
this is the errror:
parameter must be positive and < height.
Parameter name:y
How to solve this error
 
While running this code issues in some image.
this is the errror:
parameter must be positive and < height.
Parameter name:y
How to solve this error
So did you investigate the problem? What line did it occur on? The error message is telling what parameter was the issue and why it was an issue. Did you look to see what value was actually being used and examine the code to see why it isn't valid? You can actually investigate the issue for yourself. In fact, you need to investigate the issue for yourself. Even if you still can't solve the problem, at least you can provide us with far more relevant information. If you don't know how to debug code using breakpoints, etc, then you should look into that now.
 
So did you investigate the problem? What line did it occur on? The error message is telling what parameter was the issue and why it was an issue. Did you look to see what value was actually being used and examine the code to see why it isn't valid? You can actually investigate the issue for yourself. In fact, you need to investigate the issue for yourself. Even if you still can't solve the problem, at least you can provide us with far more relevant information. If you don't know how to debug code using breakpoints, etc, then you should look into that now.

I think Some images size are very big,so this error is occurring, how to solve
 
Thread split, post doesn't pertain to original (and very old) thread.
 
I think Some images size are very big,so this error is occurring, how to solve
You don't need to make vague guesses. You can determine specifics by debugging. You're not going to get far if you refuse to debug your code.
 
After Debugging this error is there.
We already know that the exception is thrown. The debugger tells you exactly what line it is thrown on, which you haven't told us. When the exception is thrown, you can use the debugger to determine the values of all your variables and any other relevant expressions, which you clearly haven't done. You need to use the tools at your disposal to get all the information you can. As I said, even if you still can't work out what the issue is, at least you can provide us with all the relevant information. There is a lot that you can do that you have not done. If you don't know how to debug code, use a search engine to find information on how to do it, then do it, then report what you find.
 
After Debugging this error is there.

Then you should be able to answer jmc's questions:

What line did it occur on? The error message is telling what parameter was the issue and why it was an issue. Did you look to see what value was actually being used and examine the code to see why it isn't valid?
 
There is no need to be rude.

If you would like to receive further help, I suggest changing your tone.

What you are being advised to do is something you need to do. We don't have access to your PC to debug your code for you. Debugging is a part of everyday programming, and it's something you should know how to do.

If you are looking to get a comparison on two images, you are going about it wrong. I'm only assuming since you never explained what you're doing, but if you want to compare them in the way you are doing it, then get each pixel to array and compare the array of each file. Alternatively, if you are trying to establish if its the same file, you should use the MD5 Class (System.Security.Cryptography) and check the files MD5 sum. However, going with the first one, I think you will find Bob Powells work worth looking at on this subject Using the LockBits method to access image data
 
There is no need to be rude.

If you would like to receive further help, I suggest changing your tone.

What you are being advised to do is something you need to do. We don't have access to your PC to debug your code for you. Debugging is a part of everyday programming, and it's something you should know how to do.

If you are looking to get a comparison on two images, you are going about it wrong. I'm only assuming since you never explained what you're doing, but if you want to compare them in the way you are doing it, then get each pixel to array and compare the array of each file. Alternatively, if you are trying to establish if its the same file, you should use the MD5 Class (System.Security.Cryptography) and check the files MD5 sum. However, going with the first one, I think you will find Bob Powells work worth looking at on this subject Using the LockBits method to access image data
i got the answer.
 
Back
Top