对象引用对象错误的实例(Bitmap)VB.NET

时间:2016-04-17 20:06:22

标签: vb.net image bitmap basic

我的Class1代码; (此代码来自类库)

    Class SuperPicBox : Inherits PictureBox
    #Region "Effects"
    Dim bin As Image = MyBase.Image
    Private roma As Boolean
    Public Property Grayscale As Boolean
        Get
            Return roma
        End Get
        Set(value As Boolean)
            roma = value
            Select Case roma
                Case True
                    Dim bm As New Bitmap(bin)            'Error here
                    Dim X As Integer
                    Dim Y As Integer
                    Dim clr As Integer

                    For X = 0 To bm.Width - 1
                        For Y = 0 To bm.Height - 1
                            clr = (CInt(bm.GetPixel(X, Y).R) + _
                                   bm.GetPixel(X, Y).G + _
                                   bm.GetPixel(X, Y).B) \ 3
                            bm.SetPixel(X, Y, Color.FromArgb(clr, clr, clr))
                        Next Y
                    Next X

                    bin = bm

                Case False
                    MyBase.Image = MyBase.Image
            End Select
            Invalidate()
        End Set
    End Property
#End Region
End Class

和此表单1按钮1单击事件代码

SuperPicBox1.Grayscale = True

我点击了button1。但不工作!我得到了Object reference to an instance of an object error

0 个答案:

没有答案