Option Strict Off
Option Explicit On

Imports System.IO

Friend Class GraphicEditor
    Inherits System.Windows.Forms.Form

    Public itemnum As Short
    Public ItemType As String
    Public itemdata As MemoryStream
    Public itemlen As Integer
    Dim pixels() As Byte
    Dim pixelarray() As Byte
    Dim numpixels As Integer
    Dim pwidth As Integer
    Dim pheight As Integer
    Dim bmpnum As Integer
    Dim maskbmpnum As Integer

    Dim ColorButton As Label()


    Public Sub init()

        'ItemType = App.mapfile.gettype(itemnum)
        'itemdata = App.graphics.itemstr(itemnum + 1)
        'itemlen = App.graphics.itemsize(itemnum + 1)
        itemdata = App.graphics.getgitemdata(itemnum)
        itemlen = graphics.getgitemsize(itemnum)

        init_contents()
    End Sub
    '	Public Function read_byte(ByVal data As String, ByVal offset As Short) As Byte
    ''UPGRADE_ISSUE: MidB function is not supported. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="367764E5-F3F8-4E43-AC3E-7FE0B5E074E2"'
    ''UPGRADE_ISSUE: AscB function is not supported. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="367764E5-F3F8-4E43-AC3E-7FE0B5E074E2"'
    '	read_byte = AscB(MidB(data, offset, 1))
    'End Function
    'Public Function read_word(ByVal data As String, ByVal offset As Short) As Integer
    '    read_word = read_byte(data, offset) * &H100
    '    read_word = read_word + read_byte(data, offset + 1)
    'End Function
    Sub write_byte(ByVal num As Byte)
        'UPGRADE_WARNING: Put was upgraded to FilePut and has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
        FilePut(140, num)
    End Sub
    Sub write_word(ByVal num As Short)
        Dim b1 As Byte
        Dim b2 As Byte
        Dim l1 As Integer
        l1 = num And &HFF00
        b1 = l1 / &H100
        b2 = num And &HFF
        write_byte(b2)
        write_byte(b1)
    End Sub
    Sub write_long(ByVal num As Integer)
        Dim b2, b1, b3, b4 As Byte
        Dim l1 As Integer
        l1 = num And &HFF000000
        b1 = l1 / &H1000000
        l1 = num And 16711424
        b2 = l1 / &H10000
        l1 = num And 65280
        b3 = l1 / &H100
        b4 = num And 255
        write_byte(b4)
        write_byte(b3)
        write_byte(b2)
        write_byte(b1)
    End Sub

    'UPGRADE_NOTE: graphics was upgraded to graphics_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    Public Sub init_contents()
        Dim imagecount As Integer
        Dim j As Integer
        Dim i As Integer
        Dim mon As Integer

        'pwidth = read_word(itemdata, 1)
        'pheight = read_word(itemdata, 3)
        pwidth = graphics.getgbitmapwidth(itemnum)
        pheight = graphics.getgbitmapheight(itemnum)

        'graphics.resetmodifiedcolorarray

        If itemnum = 1 Then
            graphics.curPalette = graphics.gPALETTE_TITLE
        ElseIf itemnum >= 2 And itemnum <= 4 Then  'Main menu pallette
            graphics.curPalette = graphics.gPALETTE_MAINMENU
        ElseIf itemnum = 5 Then  'credits pallette
            graphics.curPalette = graphics.gPALETTE_CREDITS
        ElseIf itemnum >= 446 And itemnum < 532 Then  ' creatures
            'j = 447
            graphics.copypalette(graphics.gPALETTE_MAIN, graphics.gPALETTE_CUSTOM)
            graphics.curPalette = graphics.gPALETTE_CUSTOM
            mon = -1
            For i = 1 To 27
                j = graphics.f558.monstergraphicinfo(i).graphicnum + 446
                imagecount = 1
                If graphics.f559.monster(i).w4_sideimage Then
                    imagecount = imagecount + 1
                End If
                If graphics.f559.monster(i).w4_backimage Then
                    imagecount = imagecount + 1
                End If
                'If graphics.f559.monster(i).w4_attackimage Then
                imagecount = imagecount + 1
                'End If
                If itemnum >= j And itemnum < j + imagecount Then
                    mon = i
                    i = 28
                End If
            Next
            If mon >= 0 Then
                Me.TransButton.BackColor = graphics.getpalette(graphics.curPalette, graphics.f558.monstergraphicinfo(mon).transparentpixel)
                If graphics.f558.monstergraphicinfo(mon).colora > 0 Then
                    graphics.setpalette(graphics.gPALETTE_CUSTOM, 10, graphics.f558.palettetocolor(graphics.f558.palette(graphics.f558.monstergraphicinfo(mon).colora, 1)))
                    'graphics.setmodifiedcolor 11, graphics.f558.palettetocolor(graphics.f558.palette(graphics.f558.monstergraphicinfo(mon).ColorA, 1))
                End If
                If graphics.f558.monstergraphicinfo(mon).colorb > 0 Then
                    graphics.setpalette(graphics.gPALETTE_CUSTOM, 9, graphics.f558.palettetocolor(graphics.f558.palette(graphics.f558.monstergraphicinfo(mon).colorb, 1)))
                    'graphics.setmodifiedcolor 10, graphics.f558.palettetocolor(graphics.f558.palette(graphics.f558.monstergraphicinfo(mon).ColorB, 1))
                End If
            End If

            'MsgBox "Mon: " + Str(mon)

        Else
            graphics.curPalette = graphics.gPALETTE_MAIN
        End If

        For i = 0 To 15
            ColorButton(i).BackColor = graphics.getpalette(graphics.curPalette, i)
        Next
        'Graphic.Width = pwidth
        'Graphic.Height = pheight
        'App.graphics.export_img1 itemdata, "temp.bmp"
        'THIS IS WHAT WE WANT TO GET RID OF AND REPLACE!
        'Graphic.Picture = graphics.loadgraphic(itemnum, 0)
        'YES I SAID THIS!!!!!!!!!!!!!!
        Graphic.Width = pwidth + 4
        Graphic.Height = pheight + 4

        pwidth = 337
        If Graphic.Width > 337 Then
            pwidth = Graphic.Width
        End If
        pheight = 297
        If Graphic.Height > 297 Then
            pheight = Graphic.Height
        End If


        'For i = 0 To ColorButton.Length - 1
        'ColorButton(i).Left = 15 + pwidth
        'Next
        'ST1.Left = 15 + pwidth

        'Ok.Top = 15 + pheight
        'Cancel.Top = 15 + pheight
        '7Import.Top = 15 + pheight
        'Export.Top = 15 + pheight
        'Import.Left = pwidth - 161
        'Export.Left = pwidth - 65
        'Cancel.Left = pwidth + 31

        'Height = pheight + 73
        'Width = pwidth + 136

        Dim offscreen As Bitmap = New Bitmap(Graphic.ClientSize.Width, Graphic.ClientSize.Height)
        Using cv As Drawing.Graphics = Drawing.Graphics.FromImage(offscreen)
            graphics.drawbmp(cv, itemnum)
        End Using
        Graphic.Image = offscreen

    End Sub

    Private Sub Cancel_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Cancel.Click
        'Unload Me
        'Hide
        Me.Close()
    End Sub

    'UPGRADE_NOTE: mapfile was upgraded to mapfile_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    Private Sub Export_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Export.Click
        Dim sfile As String

        Dim dlg As New SaveFileDialog
        'UPGRADE_WARNING: CommonDialog variable was not upgraded Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="671167DC-EA81-475D-B690-7A40C7BF4A23"'
        With dlg
            .Title = "Export"
            'UPGRADE_WARNING: The CommonDialog CancelError property is not supported in Visual Basic .NET. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="8B377936-3DF7-4745-AA26-DD00FA5B9BE1"'
            '.CancelError = True
            'UPGRADE_WARNING: MSComDlg.CommonDialog property MainWindow.dlg.Flags was upgraded to MainWindow.dlgSave.OverwritePrompt which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
            .OverwritePrompt = True
            'ToDo: set the flags and attributes of the common dialog control
            'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
            .Filter = "*.bmp|*.bmp|All Files (*.*)|*.*||"
            'UPGRADE_WARNING: Couldn't resolve default property of object mapfile.getname. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            .FileName = CStr((zerostr(itemnum, 4) & " ") + mapfile.getname(itemnum) + (".bmp"))
            If .ShowDialog() <> DialogResult.OK Then GoTo canceled
            'UPGRADE_WARNING: CommonDialog property MainWindow.dlg.FileTitle was upgraded to MainWindow.dlg.FileName which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
            If Len((New System.IO.DirectoryInfo(.FileName)).Name) = 0 Then
                Exit Sub
            End If
            sfile = .FileName
            'curlevel = 0

        End With

        App.graphics.kkspec_gexport_img1_type2(itemnum, sfile, 0)
        'App.graphics.export_img1 itemdata, sfile, False
canceled:
    End Sub





    'UPGRADE_NOTE: mapfile was upgraded to mapfile_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    'UPGRADE_NOTE: graphics was upgraded to graphics_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    Private Sub Import_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Import.Click
        Dim imagecount As Integer
        Dim j As Integer
        Dim i As Integer
        Dim mon As Integer
        Dim f As FileInfo
        Dim sfile As String

        Dim dlg As New OpenFileDialog
        'UPGRADE_WARNING: CommonDialog variable was not upgraded Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="671167DC-EA81-475D-B690-7A40C7BF4A23"'
        With dlg
            .Title = "Import"
            'UPGRADE_WARNING: The CommonDialog CancelError property is not supported in Visual Basic .NET. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="8B377936-3DF7-4745-AA26-DD00FA5B9BE1"'
            '.CancelError = True
            'ToDo: set the flags and attributes of the common dialog control
            'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
            .Filter = "*.bmp|*.bmp|All Files (*.*)|*.*||"
            'UPGRADE_WARNING: Couldn't resolve default property of object mapfile.getname. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            .FileName = CStr((zerostr(itemnum, 4) & " ") + mapfile.getname(itemnum) + (".bmp"))
            If .ShowDialog() <> Windows.Forms.DialogResult.OK Then GoTo canceled
            'UPGRADE_WARNING: CommonDialog property MainWindow.dlg.FileTitle was upgraded to MainWindow.dlg.FileName which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
            If Len((New System.IO.DirectoryInfo(.FileName)).Name) = 0 Then
                Exit Sub
            End If
            'curlevel = 0
            'UPGRADE_WARNING: Couldn't resolve default property of object fs.GetFile. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            f = New FileInfo(.FileName)
            'UPGRADE_WARNING: CommonDialog property MainWindow.dlg.FileTitle was upgraded to MainWindow.dlg.FileName which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
            sfile = .FileName
            'UPGRADE_WARNING: Couldn't resolve default property of object f.Size. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            itemlen = f.Length

        End With


        'first setup the palette
        If itemnum = 1 Then
            'UPGRADE_WARNING: Couldn't resolve default property of object graphics.curPalette. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            'UPGRADE_WARNING: Couldn't resolve default property of object graphics.gPALETTE_TITLE. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            graphics.curPalette = graphics.gPALETTE_TITLE
        ElseIf itemnum >= 2 And itemnum <= 4 Then  'Main menu pallette
            'UPGRADE_WARNING: Couldn't resolve default property of object graphics.curPalette. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            'UPGRADE_WARNING: Couldn't resolve default property of object graphics.gPALETTE_MAINMENU. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            graphics.curPalette = graphics.gPALETTE_MAINMENU
        ElseIf itemnum = 5 Then  'credits pallette
            'UPGRADE_WARNING: Couldn't resolve default property of object graphics.curPalette. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            'UPGRADE_WARNING: Couldn't resolve default property of object graphics.gPALETTE_CREDITS. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            graphics.curPalette = graphics.gPALETTE_CREDITS
        ElseIf itemnum >= 446 And itemnum < 532 Then  ' creatures
            'j = 447
            'UPGRADE_WARNING: Couldn't resolve default property of object graphics.gPALETTE_CUSTOM. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            'UPGRADE_WARNING: Couldn't resolve default property of object graphics.gPALETTE_MAIN. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            'UPGRADE_WARNING: Couldn't resolve default property of object graphics.copypalette. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            graphics.copypalette(graphics.gPALETTE_MAIN, graphics.gPALETTE_CUSTOM)
            'UPGRADE_WARNING: Couldn't resolve default property of object graphics.curPalette. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            'UPGRADE_WARNING: Couldn't resolve default property of object graphics.gPALETTE_CUSTOM. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            graphics.curPalette = graphics.gPALETTE_CUSTOM
            mon = -1
            For i = 1 To 27
                'UPGRADE_WARNING: Couldn't resolve default property of object graphics.f558. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                'UPGRADE_WARNING: Couldn't resolve default property of object j. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                j = graphics.f558.monstergraphicinfo(i).graphicnum + 446
                imagecount = 1
                'UPGRADE_WARNING: Couldn't resolve default property of object graphics.f559. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                If graphics.f559.monster(i).w4_sideimage Then
                    imagecount = imagecount + 1
                End If
                'UPGRADE_WARNING: Couldn't resolve default property of object graphics.f559. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                If graphics.f559.monster(i).w4_backimage Then
                    imagecount = imagecount + 1
                End If
                'If graphics.f559.monster(i).w4_attackimage Then
                imagecount = imagecount + 1
                'End If
                'UPGRADE_WARNING: Couldn't resolve default property of object j. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                If itemnum >= j And itemnum < j + imagecount Then
                    'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                    mon = i
                    'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                    i = 28
                End If
            Next
            If mon >= 0 Then
                'UPGRADE_WARNING: Couldn't resolve default property of object graphics.f558. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                'UPGRADE_WARNING: Couldn't resolve default property of object graphics.curPalette. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                'UPGRADE_WARNING: Couldn't resolve default property of object graphics.getpalette. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                Me.TransButton.BackColor = graphics.getpalette(graphics.curPalette, graphics.f558.monstergraphicinfo(mon).transparentpixel)
                'UPGRADE_WARNING: Couldn't resolve default property of object graphics.f558. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                If graphics.f558.monstergraphicinfo(mon).colora > 0 Then
                    'UPGRADE_WARNING: Couldn't resolve default property of object graphics.f558. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                    'UPGRADE_WARNING: Couldn't resolve default property of object graphics.gPALETTE_CUSTOM. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                    'UPGRADE_WARNING: Couldn't resolve default property of object graphics.setpalette. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                    graphics.setpalette(graphics.gPALETTE_CUSTOM, 10, graphics.f558.palettetocolor(graphics.f558.palette(graphics.f558.monstergraphicinfo(mon).colora, 1)))
                    'graphics.setmodifiedcolor 11, graphics.f558.palettetocolor(graphics.f558.palette(graphics.f558.monstergraphicinfo(mon).ColorA, 1))
                End If
                'UPGRADE_WARNING: Couldn't resolve default property of object graphics.f558. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                If graphics.f558.monstergraphicinfo(mon).colorb > 0 Then
                    'UPGRADE_WARNING: Couldn't resolve default property of object graphics.f558. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                    'UPGRADE_WARNING: Couldn't resolve default property of object graphics.gPALETTE_CUSTOM. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                    'UPGRADE_WARNING: Couldn't resolve default property of object graphics.setpalette. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                    graphics.setpalette(graphics.gPALETTE_CUSTOM, 9, graphics.f558.palettetocolor(graphics.f558.palette(graphics.f558.monstergraphicinfo(mon).colorb, 1)))
                    'graphics.setmodifiedcolor 10, graphics.f558.palettetocolor(graphics.f558.palette(graphics.f558.monstergraphicinfo(mon).ColorB, 1))
                End If
            End If

            'MsgBox "Mon: " + Str(mon)

        Else
            'UPGRADE_WARNING: Couldn't resolve default property of object graphics.curPalette. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            'UPGRADE_WARNING: Couldn't resolve default property of object graphics.gPALETTE_MAIN. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
            graphics.curPalette = graphics.gPALETTE_MAIN
        End If
        'Open sFile For Binary Access Read As 138

        'itemdata = InputB(itemlen, 138)
        'MsgBox "Loading " + sFile + " into Graphic"
        Graphic.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
        Graphic.Image = MyPicUt.LoadPicFromFile(sfile)
        Graphic.Refresh()
        Graphic.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Normal
        Refresh()

        'Close 138

        '    sfile = App.apppath + "\temp.bmp"
        generatepixelarray()
        'UPGRADE_WARNING: Couldn't resolve default property of object graphics.encode_img1. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        itemdata = graphics.encode_img1(pixelarray, Graphic.Image.Width, Graphic.Image.Height)
        'UPGRADE_ISSUE: LenB function is not supported. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="367764E5-F3F8-4E43-AC3E-7FE0B5E074E2"'
        itemlen = itemdata.Length
        '    App.graphics.export_img1 itemdata, sfile, False
        '    Graphic.Picture = LoadPicture(sfile)
        ReDim pixelarray(0)
        'init_contents
canceled:

    End Sub

    'UPGRADE_NOTE: graphics was upgraded to graphics_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    Public Sub generatepixelarray()
        Dim pic As Bitmap = CType(Graphic.Image, Bitmap)

        ReDim pixelarray((pic.Width) * (pic.Height))

        Dim i As Integer
        Dim X As Integer
        Dim Y As Integer

        i = 1
        For Y = 1 To pic.Height
            For X = 1 To pic.Width

                'UPGRADE_ISSUE: PictureBox method Graphic.Point was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
                'UPGRADE_WARNING: Couldn't resolve default property of object graphics.gfindcolor. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                pixelarray(i) = graphics.gfindcolor(pic.GetPixel(X - 1, Y - 1)) And &HF

                i = i + 1
            Next
        Next


    End Sub
    'UPGRADE_NOTE: graphics was upgraded to graphics_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    Private Sub Ok_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Ok.Click
        'graphics.setitemstr itemnum, itemdata
        'graphics.setitemsize itemnum, LenB(itemdata)
        ' graphics.reloadgraphic itemnum, 0
        'UPGRADE_WARNING: Couldn't resolve default property of object graphics.setgitemdata. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        graphics.setgitemdata(itemnum, itemdata)
        'UPGRADE_WARNING: Couldn't resolve default property of object graphics.setgitemsize. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        graphics.setgitemsize(itemnum, itemlen)
        'rebuild the bmp
        'UPGRADE_WARNING: Couldn't resolve default property of object graphics.buildbmp. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        graphics.buildbmp(itemnum)
        Me.Close()
    End Sub

    Private Sub GraphicEditor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ColorButton = New Label() { _
            Label1, _
            Label2, _
            Label3, _
            Label4, _
            Label5, _
            Label6, _
            Label7, _
            Label8, _
            Label9, _
            Label10, _
            Label11, _
            Label12, _
            Label13, _
            Label14, _
            Label15, _
            Label16 _
        }
    End Sub
End Class