You must Sign In to post a response.
  • Category: .NET

    How to convert image to binary and get result in text box

    I need to convert image to binary and get result in text box .

    Image found in path D:/person.jpg

    i using the following function :




    public ArrayList imageToBinaryArray1(System.Drawing.Image imageIn)

    {

    MemoryStream ms = new MemoryStream();

    byte[] arr = new byte[50000000];

    ArrayList al = new ArrayList();

    imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);

    arr= ms.ToArray();

    foreach (byte item in arr)

    {

    al.Add(Convert.ToString(item, 2));

    }

    return al;

    }

    How to receive the value returned from function imageToBinaryArray1 in textbox1 ?

    I work in c# windows form c#
  • #768627
    This is the example of code snippet for convert image to binary and get result in text box
    Bitmap img;
    img = new Bitmap(openFileDialog1.FileName.ToString())
    string texto = "";
    for (int i = 0; i < img.Width; i++)
    {
    for (int j = 0; j < img.Height; j++)
    {
    if (img.GetPixel(j, i).A.ToString() == "255" && img.GetPixel(j,
    i).B.ToString() == "255" && img.GetPixel(j, i).G.ToString() ==
    "255" && img.GetPixel(j, i).R.ToString() == "255")
    {
    texto = texto + "0";
    }
    else
    {
    texto = texto + "1";
    }
    }
    texto = texto + "\r\n";
    }
    txtArreglo.Text = texto;


    Reference: https://www.codeproject.com/Questions/85143/Convert-image-in-binary-format-using-c

    http://www.c-sharpcorner.com/article/convert-image-to-binary/


Sign In to post your comments