Turning a picture to white and black only
Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Hi guys how would I would I go about this I want to change from colored to white and black hehaho;
hello sky
this will do the job
i hope you mean grayscale?
this will do the job
i hope you mean grayscale?
Code: Select all
use it like this:
Public Function grayscale(ByVal img As Image) As Boolean
Dim cm As New System.Drawing.Imaging.ColorMatrix(New Single()() _
{New Single() {0.299, 0.299, 0.299, 0, 0}, _
New Single() {0.587, 0.587, 0.587, 0, 0}, _
New Single() {0.114, 0.114, 0.114, 0, 0}, _
New Single() {0, 0, 0, 1, 0}, _
New Single() {0, 0, 0, 0, 1}})
Return drawImage(img, cm)
End Function
Code: Select all
Dummy1912grayscale(PictureBox1.Image)
PictureBox1.Invalidate()
visit us on:
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
try this black and white
Code: Select all
Imports System.Drawing
Imports System.Drawing.Imaging
Dim bitmap As Bitmap
bitmap = New Bitmap( Me.Picture1.Image)
Dim x, y
Dim d As Byte
For x = 0 To Me.Picture.Image.Width - 1
For y = 0 To Me.Picture.Image.Height - 1
d = Math.Round((bitmap.GetPixel(x, y).R * 0.299 + bitmap.GetPixel(x, y).G * 0.587 + bitmap.GetPixel(x, y).B * 0.114))
bitmap.SetPixel(x, y, Color.FromArgb(d, d, d))
Next y
Next x
Me.Picture1.Image = bitmap
visit us on:
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
hey i get an error on drawimage(img, cm) 'drawimage' is not declared. It may be inaccessible due to its protection level.
tryed to declare it and still gives me error
tryed to declare it and still gives me error
did you import this
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing
Imports System.Drawing.Imaging
visit us on:
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
hmmm
is drawimage a picturebox?
so you need to do:
is drawimage a picturebox?
so you need to do:
Code: Select all
but it must workdrawimage.image = openfiledialog1.filename
visit us on:
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
Code: Select all
I guess that will workPublic Sub BlackWhite(ByVal img As Bitmap)
Dim bmd As BitmapData = img.LockBits(New Rectangle(Point.Empty, img.Size), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)
Dim data(0 To bmd.Stride * bmd.Height) As Byte
Marshal.Copy(bmd.Scan0, data, 0, data.Length)
Dim r, g, b As Byte
For y = 0 To img.Height
For x = 0 To img.Width
b = data(y * bmd.Stride + x * 3)
g = data(y * bmd.Stride + x * 3 + 1)
r = data(y * bmd.Stride + x * 3 + 2)
If b + g + r > 381 Then
data(y * bmd.Stride + x * 3) = 255
data(y * bmd.Stride + x * 3 + 1) = 255
data(y * bmd.Stride + x * 3 + 2) = 255
Else
data(y * bmd.Stride + x * 3) = 0
data(y * bmd.Stride + x * 3 + 1) = 0
data(y * bmd.Stride + x * 3 + 2) = 0
End If
Next
Next
Marshal.Copy(data, bmd.Scan0, 0, data.Length)
img.UnlockBits(bmd)
End Sub
EDIT!!
I made an awful mistake, I swapped height and width. Now it will work
Last edited by MrAksel on Sun Jan 29, 2012 9:14 pm, edited 1 time in total.
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
![Image]()
![Image]()
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!

Yup it works but its it turns red into gray and my OCR cant recognize it I would need the black to turn to white and the red to turn to white and the white to turn to black since some text is white oh and green to white to


You can change the value 381 to something lower if you want more to turn white. Or make it higher if more is to turend black.
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
![Image]()
![Image]()
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!

Copyright Information
Copyright © Codenstuff.com 2020 - 2023