|
-
Aug 27th, 2002, 05:53 PM
#1
Thread Starter
Fanatic Member
REsizing Images
I'm writing a OCR program (handwriting recognition acutally), and I need some sort of way to take the image data from a Picturebox (stuff isi drawn to it with the Graphics class), resize it (using nearest neighbor resampling), and convert to pure B+W and generate a bitboard of 1s and 0s indicating which pixels are black and which are white.
please direct me to success... 
-C
-
Aug 28th, 2002, 09:15 AM
#2
Thread Starter
Fanatic Member
-
Aug 28th, 2002, 04:52 PM
#3
Member
Hey comrade, I don't know jack about resizing or rescaling images, But this might help to create your bit array from a bitmap.
Dim i, j As Integer
Dim myBitmap As System.Drawing.Bitmap
Dim tmpColor As System.Drawing.Color
myBitmap = New System.Drawing.Bitmap(myPictureBox.Image)
For i = 0 To (myBitmap.Width - 1)
For j = 0 To (myBitmap.Height - 1)
tmpColor = myBitmap.GetPixel(i, j)
If (tmpColor.R = 255) AndAlso (tmpColor.G = 255) AndAlso (tmpColor.B = 255) Then
'This is the white color, background color for example
Else
'This is not white color, a user drawn pixel
End If
Next j
Next i
Good Luck.
-
Aug 28th, 2002, 05:12 PM
#4
Thread Starter
Fanatic Member
thanks 
i'm still wroking on the resizing issue but if need be I can write code to resize it manually with your code...it'll be arse slow to do but hey it works 
-C
-
Aug 28th, 2002, 05:26 PM
#5
Thread Starter
Fanatic Member
whoa one question....
i used the picturebox.creategraphics function to get a graphics object, which i used to draw on the picture box.... and for some reason picturebox.image remains nothing, even though stuff's been drawn, so i can't instantiate a new bitmap obejct from picturebox.image...
anybody know how i cam work around this?
_C
-
Aug 29th, 2002, 08:42 PM
#6
Member
Hey comrade, Sorry! I think there is a misunderstanding here. PictureBox will NOT save your drawings in its own 'Image' property, I told you to use 'Image' property because I thought that you've done this part before (Believe me, I'm not always such a fool. Just sometimes.) You have to save user input for the case of redrawing your PictureBox (With the Bitmap.SetPixel method, not quiet an easy job!) Consider user draws a pretty char to recognize and then he switch to another app to do something. That App might cover yours, when he is coming back, what does he see? Nothing! (Maybe some parts of his drawing.) And what is better to save user input than 'Image' property? However, there is another way: get the pixels directly from the screen and forget about App switching. Although I don't recommend you that, but here is some code to do the stuff, Just remember:
1- According to my knowledge, getting pixel colors from screen is not supported in GDI+ anymore (I'm not sure), so I had to use GDI, BAD IDEA.
2- Reading pixels from screen is not a good approach for a Pro App. Remember always-on-top forms?
Code:
Private Declare Auto Function CreateDC Lib "gdi32" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As IntPtr) As Integer
Private Declare Auto Function DeleteDC Lib "gdi32" (ByVal hdc As Integer) As Integer
Private Declare Auto Function GetPixel Lib "gdi32" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer) As Integer
Private Sub myButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles myButton.Click
Dim i, j, tmpDC, tmpRgbColor As Integer
Dim tmpPoint As System.Drawing.Point
tmpDC = CreateDC("DISPLAY", Nothing, Nothing, Nothing)
For i = myPictureBox.ClientRectangle.Left To myPictureBox.ClientRectangle.Right
For j = myPictureBox.ClientRectangle.Top To myPictureBox.ClientRectangle.Bottom
tmpPoint.X = i
tmpPoint.Y = j
tmpPoint = myPictureBox.PointToScreen(tmpPoint)
tmpRgbColor = GetPixel(tmpDC, tmpPoint.X, tmpPoint.Y)
If (tmpRgbColor And &HFFFFFF) = &HFFFFFF Then
'White color, Background color for example
Else
'Another color, User drawn pixel
End If
Next j
Next i
DeleteDC(tmpDC)
End Sub
Good Luck.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|