Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change the colors of an image and still have it reconized by the code?
    primarykey
    data
    text
    <p>this is my first time asking a question here, so please be kind.</p> <p>This is for a small game I'm making in Visual Basic 2010. I have an image that, when clicked on, is darkened. I need it to to be recognized later by the code as the same as the original image.</p> <p>Here's the code to darken the image:</p> <pre><code>Sub WaterDarken(ByVal picTarget As PictureBox) Dim pic As New Bitmap(picTarget.Image) Dim intRed As Integer Dim intGreen As Integer Dim intBlue As Integer For x As Integer = 0 To picTarget.Image.Width - 1 For y As Integer = 0 To picTarget.Image.Height - 1 Dim intDarkenedColor As Color = pic.GetPixel(x, y) If intDarkenedColor.R - 50 &lt;= 255 And intDarkenedColor.R - 50 &gt;= 0 Then intRed = intDarkenedColor.R - 50 Else intRed = 0 End If If intDarkenedColor.G - 50 &lt;= 255 And intDarkenedColor.G - 50 &gt;= 0 Then intGreen = intDarkenedColor.G - 50 Else intGreen = 0 End If If intDarkenedColor.B - 50 &lt;= 255 And intDarkenedColor.B - 50 &gt;= 0 Then intBlue = intDarkenedColor.B - 50 Else intBlue = 0 End If intDarkenedColor = Color.FromArgb(225, intRed, intGreen, intBlue) pic.SetPixel(x, y, intDarkenedColor) Next Next picTarget.Image = pic End Sub </code></pre> <p>And here is the code to compare the original image to the darkened one:</p> <pre><code> Function IsDarkened(ByRef source As Image, ByRef darkenedSource As Image) As Boolean Dim pic As New Bitmap(source) Dim pic2 As New Bitmap(darkenedSource) Dim intRed As Integer Dim intGreen As Integer Dim intBlue As Integer For x As Integer = 0 To pic.Width - 1 For y As Integer = 0 To pic.Height - 1 Dim darkened As Color = pic.GetPixel(x, y) If darkened.R - 50 &lt;= 255 And darkened.R - 50 &gt;= 0 Then intRed = darkened.R - 50 Else intRed = 0 End If If darkened.G - 50 &lt;= 255 And darkened.G - 50 &gt;= 0 Then intGreen = darkened.R - 50 Else intGreen = 0 End If If darkened.B - 50 &lt;= 255 And darkened.B - 50 &gt;= 0 Then intBlue = darkened.B - 50 Else intBlue = 0 End If darkened = Color.FromArgb(255, intRed, intGreen, intBlue) pic.SetPixel(x, y, darkened) Next Next For x = 0 To pic.Width - 1 For y = 0 To pic.Height - 1 If pic.GetPixel(x, y) &lt;&gt; pic2.GetPixel(x, y) Then Return False End If Next Next Return True End Function </code></pre> <p>However, something isn't working, and the images aren't being noticed as the same. This has been bothering me for some time. If any of you can help, please do so! Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload