Click here to Skip to main content
15,887,875 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: How Many versions of the CLR can be installed on a computer ??? Pin
Derek Tortonian20-May-16 8:58
Derek Tortonian20-May-16 8:58 
QuestionConnecting to SQL database Pin
Member 1228398616-May-16 1:53
Member 1228398616-May-16 1:53 
AnswerRe: Connecting to SQL database Pin
Dave Kreskowiak16-May-16 2:47
mveDave Kreskowiak16-May-16 2:47 
GeneralRe: Connecting to SQL database Pin
Member 1228398616-May-16 2:57
Member 1228398616-May-16 2:57 
QuestionExporting excel chart to PNG - a generic error occurred in GDI+ - VB.NET Pin
WesselVB16-May-16 0:37
WesselVB16-May-16 0:37 
AnswerRe: Exporting excel chart to PNG - a generic error occurred in GDI+ - VB.NET Pin
Simon_Whale16-May-16 0:52
Simon_Whale16-May-16 0:52 
AnswerRe: Exporting excel chart to PNG - a generic error occurred in GDI+ - VB.NET Pin
Richard Deeming16-May-16 1:04
mveRichard Deeming16-May-16 1:04 
Questionsystem overflow exception on an arithmetic operation Pin
Member 1063639915-May-16 0:11
Member 1063639915-May-16 0:11 
Hi there,

I try to use a code from your site: href="http://www.codeproject.com/Articles/617613/Fast-pixel-operations-in-NET-with-and-without-unsa

in VB.NET.

I get: a system overflow exception in my code below.

Quote:
Dim diffR As Integer = CInt(pixelR - searchedR) '<=================
' pixelR is 128, searchedR is 0



I assume, that the code is correct where the exception pops up. Can you have a look at my code?

Thanks for any help

Bernd

<blockquote class="quote"><div class="op">Quote:</div>Function true_Black_and_White_Unsafe_Methode( _
        MyImage As Image,
        searchedR As Byte, searchedG As Byte, searchedB As Byte, _
        Tolerance As Integer) As Image

        ' Source:
        ' http://www.codeproject.com/Articles/617613/Fast-pixel-operations-in-NET-with-and-without-unsa

        Dim Bmp8 As New Bitmap(MyImage.Width, MyImage.Height, PixelFormat.Format1bppIndexed)
        Dim imageData As BitmapData = Bmp8.LockBits(New Rectangle(0, 0, MyImage.Width, _
            MyImage.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)

        Dim bytesPerPixel As Integer = 3
        Dim scan0 As Integer = imageData.Scan0
        Dim stride As Integer = imageData.Stride

        Dim unmatchingValue As Byte = 0
        Dim matchingValue As Byte = 255
        Dim toleranceSquared As Integer = Tolerance * Tolerance
        Dim y As Integer
        For y = 0 To imageData.Height - 1

            Dim row(scan0 + (y * stride)) As Integer
            Dim x As Integer
            For x = 0 To imageData.Width - 1

                ' Watch out for actual order (BGR)!
                Dim bIndex As IntPtr = x * bytesPerPixel
                Dim gIndex As IntPtr = bIndex + 1
                Dim rIndex As IntPtr = bIndex + 2

                Dim pixelR As Byte = row(rIndex)
                Dim pixelG As Byte = row(gIndex)
                Dim pixelB As Byte = row(bIndex)

                ' here is the system overflow exception
                Dim diffR As Integer = CInt(pixelR - searchedR) '<================= 
' pixelR is 128, searchedR is 0</blockquote>

                
Dim diffR As Integer = CInt(pixelR - searchedR) '<================= 
' pixelR is 128, searchedR is 0

                Dim diffG As Integer = CInt(pixelG - searchedG)
                Dim diffB As Integer = CInt(pixelB - searchedB)

                Dim distance As Integer = diffR * diffR + diffG * diffG + diffB * diffB

                If distance > toleranceSquared Then
                    row(rIndex) = row(bIndex) = row(gIndex) = unmatchingValue
                Else
                    row(rIndex) = row(bIndex) = row(gIndex) = matchingValue
                End If
            Next
        Next

        Bmp8.UnlockBits(imageData)
        Return Bmp8
    End Function</blockquote>

AnswerRe: system overflow exception on an arithmetic operation Pin
Dave Kreskowiak15-May-16 3:09
mveDave Kreskowiak15-May-16 3:09 
QuestionCOM Interop Pin
JackMisani9-May-16 7:16
JackMisani9-May-16 7:16 
AnswerRe: COM Interop Pin
Nathan Minier10-May-16 1:20
professionalNathan Minier10-May-16 1:20 
GeneralRe: COM Interop Pin
JackMisani10-May-16 2:28
JackMisani10-May-16 2:28 
GeneralRe: COM Interop Pin
Dave Kreskowiak10-May-16 5:02
mveDave Kreskowiak10-May-16 5:02 
SuggestionRe: COM Interop Pin
Richard Deeming10-May-16 8:02
mveRichard Deeming10-May-16 8:02 
GeneralRe: COM Interop Pin
Nathan Minier11-May-16 1:19
professionalNathan Minier11-May-16 1:19 
QuestionSmtpClient not working in Windows Server 2012 R2 Pin
drentsch9-May-16 5:09
drentsch9-May-16 5:09 
AnswerRe: SmtpClient not working in Windows Server 2012 R2 Pin
Nathan Minier10-May-16 1:22
professionalNathan Minier10-May-16 1:22 
GeneralRe: SmtpClient not working in Windows Server 2012 R2 Pin
drentsch10-May-16 1:43
drentsch10-May-16 1:43 
Questioncode working on one pc on on another not... Pin
Member 124732905-May-16 22:18
Member 124732905-May-16 22:18 
GeneralRe: code working on one pc on on another not... Pin
Richard MacCutchan5-May-16 23:12
mveRichard MacCutchan5-May-16 23:12 
GeneralRe: code working on one pc on on another not... Pin
Member 124732906-May-16 0:55
Member 124732906-May-16 0:55 
GeneralRe: code working on one pc on on another not... Pin
Richard MacCutchan6-May-16 2:52
mveRichard MacCutchan6-May-16 2:52 
GeneralRe: code working on one pc on on another not... Pin
Member 124732907-May-16 8:07
Member 124732907-May-16 8:07 
GeneralRe: code working on one pc on on another not... Pin
Richard MacCutchan7-May-16 20:40
mveRichard MacCutchan7-May-16 20:40 
GeneralRe: code working on one pc on on another not... Pin
Member 124732908-May-16 5:49
Member 124732908-May-16 5:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.