开发者

Why is this not showing any results in PictureBox?

I'm trying to change an image to black and white on a variable threshold for use in an ocr program. My problem is that I'm not seeing any results in the image that is supposedly processed. I do experience a small开发者_如何学Go wait when rendering, so i am to assume that it is actually doing something.

Imports System.Object
Imports System.Drawing.Bitmap

Public Class Form1
    Dim x As Integer, y As Integer
    Dim imgx As Integer, imgy As Integer
    Dim img As Bitmap
    Dim thresh As Bitmap
    Dim pixelColor As Color
    Dim threshcolor As Color
    Dim tempcolor As Color

    Public Function getpixel(ByRef x As Integer, ByRef y As Integer) As Color

    End Function

    Public Sub find_img_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles find_img.Click
        open_img.ShowDialog()
        img_dsp.Text = open_img.FileName()
        img_loc.Text = open_img.FileName
        img_dsp.ImageLocation = img_dsp.Text
    End Sub

    Public Sub find_img_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles find_img.LostFocus
        img = (img_dsp.Image)
        img_dsp.Refresh()
        img_dsp.Text = open_img.FileName()
        img_dsp.ImageLocation = img_dsp.Text
        img = (img_dsp.Image)
        img_dsp.Refresh()
    End Sub

    Public Sub render_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles render.Click
        Dim myx As Integer
        Dim myy As Integer

        img_threshold.Image = img
        thresh = img_threshold.Image

        For myy = 1 To (img.Height - 1)
            For myx = 1 To (img.Width - 1)
                tempcolor = img.GetPixel(myx, myy)

                If tempcolor.GetBrightness < NumericUpDown1.Value Then
                    thresh.SetPixel(x, y, Color.Black)
                End If

                If tempcolor.GetBrightness > NumericUpDown1.Value Then
                    thresh.SetPixel(x, y, Color.White)
                End If
            Next myx
        Next myy

        img_threshold.Image = thresh
        img_threshold.Refresh()
    End Sub
End Class    


Do you know what a reference is? writing A = B, and changing A and writing B = A? if you specify that A and B point the same object (a reference to the same object) changing one changes the other too, they occupy the same storage in memory! Teach yourself basic, before writing programs, please.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜