SpriteSaver

September 12, 2018

Reading time ~2 minutes

SpriteSaver is used by my wife to erase a specific color of a bigger picture to use them in her dioramas.


Features

  • Control the program with hotkeys
    F6 pick color.
    F7 set color.
    F9 delete color.
    F10 save new image .
  • Drag the red square around to get the rough location into to preview windows.
  • Use the slider left and below the preview windows to change the size.
  • Use your mousecursor to select a specific color you want to erase

Program screenshot:
SpriteSaver


The program was written in VB.NET

Get the keyInput:

<DllImport("user32.dll")> _
    Shared Function GetAsyncKeyState(ByVal vKey As System.Windows.Forms.Keys) As Short

Move the rectangle with your mouse:

#Region "MoveRectangle"
    Private Sub pb_Source_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pb_Source.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left AndAlso myRectangle.Contains(e.Location) Then
            x = myRectangle.X - e.X
            y = myRectangle.Y - e.Y
        End If
    End Sub

    Private Sub pb_Source_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pb_Source.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left AndAlso myRectangle.Contains(e.Location) Then
            myRectangle.X = e.X + x
            myRectangle.Y = e.Y + y
            lbl_coordsOuterTopLeft.Text = "X = " & myRectangle.X & " | " & "Y = " & myRectangle.Y
            lbl_coordsInnerTopLeft.Text = "X = " & myRectangle.X + 2 & " | " & "Y = " & myRectangle.Y + 2
            lbl_coordsInnerLowerRight.Text = "X = " & num_horVal.Value - 2 & " | " & "Y = " & num_verVal.Value - 2
            pb_Source.Refresh()
            ShowPreview()
        End If
    End Sub

Remove the specified color from the image:

Sub ChangePixels()
        Dim x As Integer
        Dim y As Integer
        Dim red As Byte
        Dim green As Byte
        Dim blue As Byte

        Dim img As Bitmap = New Bitmap(pb_Preview.Image)

        For x = 0 To img.Width - 1
            For y = 0 To img.Height - 1
                red = img.GetPixel(x, y).R
                green = img.GetPixel(x, y).G
                blue = img.GetPixel(x, y).B

                If red = CDbl(tb_red.Text) AndAlso green = CDbl(tb_green.Text) AndAlso blue = CDbl(tb_blue.Text) Then
                    img.SetPixel(x, y, Color.Transparent)
                End If
            Next
        Next
        pb_Preview.Image = img
    End Sub