Convert image to binary
I've converted the image in grayscale, and I need to convert it to binary, any Ideas?!!!
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Selva GanapathyRank #560 · 4.3K reputationPosted Oct 3, 2014, 12:39 AM EDT
Hi Klajdi Paja,
Using the following code snippet you can canvert an image to a binary.
BinaryReader r = new BinaryReader();
byte[] b= r.ReadBytes(image);
Also the following article may help you to image conversion
http://www.c-sharpcorner.com/Blogs/13672/convert-a-color-image-into-black-and-white-image.aspx
Regards,
Selva Ganapathy K
Abhishek KumarRank #510 · 4.8K reputationPosted Oct 3, 2014, 1:35 AM EDT
Follow the below article.
http://www.codeproject.com/Articles/109013/Image-in-Csharp-Save-Resize-and-Convert-to-Binary
Abhishek
Hemant SrivastavaRank #581 · 4.2K reputationPosted Oct 3, 2014, 6:22 AM EDT
Here is the link where I am converting an Image into BinaryArray and a BinaryArray back to image:
http://hemant-srivastava.blogspot.com/2012/07/converting-any-image-into-bytearray-and.html
Aldemir Nolan6 reputationPosted Oct 15, 2014, 11:16 PM EDT
Some of the replies here don't seem to understand what "binary" means. I don't think you on mean "byte data", but you want "binary color", which means pure black and white. Is this correct?
The article suggested by Selva is a good approximation for converting color to grayscale. However, it neither accurately converts to grayscale nor does it convert to pure black and white like the original question.
The article calculates the gray level as the direct average of the red, green and blue values, or:
Gray = ( R + G + B) / 3
A more accurate value gives more weight to green because the human eye is much more sensitive to it. One common algorithm is this:
Gray = (0.25 R + 0.62 G + 0.13 B) / 3
However, if the goal is to convert to black and white instead of gray, more processing is needed depending on your final goal. At some stage you might be better off using a dedicated image processing library such as Leadtools.Munesh SharmaRank #174 · 13.9K reputationPosted Oct 16, 2014, 2:59 AM EDT
for more go here
http://dotnet-munesh.blogspot.in/2014/05/how-to-save-image-in-database-in-window.html
Ahmed Fahmy48 reputationPosted Sep 14, 2017, 4:44 PM EDT
Kip HackmanRank #2,595 · 536 reputationPosted Mar 3, 2021, 3:13 PM EST
Jignesh KumarRank #91 · 22.9K reputationPosted Mar 3, 2021, 11:00 PM EST