Tuesday, August 11, 2009

How To: Convert Image to String Using C#

the easy way to convert any image to string is :

1- Convert Image to Memory Stream.
2- Convert Memory Stream to Base64String.

so in this sample code I will convert the image to string and I'll save this string in text file.

private string ConvertImage(Bitmap sBit)
{
MemoryStream imageStream = new MemoryStream();
sBit.Save(imageStream, ImageFormat.Jpeg);

return Convert.ToBase64String(imageStream.ToArray());
}

private void button1_Click(object sender, EventArgs e)
{
Bitmap sBit = new Bitmap(@"C:\bmw.jpg");
string imageString = ConvertImage(sBit);

StreamWriter sw = new StreamWriter(@"C:\waleedelkot.text", false);
sw.Write(imageString);
sw.Close();
}

17 comments:

  1. dear sir can u work for me
    i can pay u a lot
    my gmail id is uday.binny@gmail.com

    i am working in data processing, i need a developer like u

    ReplyDelete
  2. Hi, How can i get this to a string array?

    ReplyDelete
  3. it's only converting the bits into pexils,

    not charaters or image processing


    please read more about OCR/ICR/OMR etc..

    ReplyDelete
  4. sir i have to prepare one project in .net.. in which i have to convert one jpg image(scan image) into text file.....
    can u tell me the code for this?
    pls help me
    emailid :- pratibha.sharma9@gmail.com

    ReplyDelete
    Replies
    1. mam have u get this if u get plz send me to sbharani.kongu@gmal.com

      Delete
    2. Hello sir/mam, i have the same project and i need source code for converting image(scan image) into text file. Can u help me too... Here's my email candranesia@gmail.com

      Delete
    3. If know any information about converting image to text. please forward those details to murthy.doddipatla@gmail.com

      Delete
  5. That was really funny, actually more funny than sBit.ToString()

    ReplyDelete
  6. Great code. Finally found my solution.

    ReplyDelete
  7. hello sir, i'm a new fan of your blog. i'm working on some project and i need source code for converting image(scan image) into text file. so please and please help me
    here is my email id successisbehindme@gmail.com

    ReplyDelete
    Replies
    1. Hello sir, i have the same project and i need source code for converting image(scan image) into text file. Can u help me too... Here's my email candranesia@gmail.com

      Delete
  8. this code can't work for converting image to text..

    ReplyDelete
  9. i need the dll for converting the image to text

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. I am doing the OCR project. I need help to convert to selected part of the scan image to text file. Please help me. Please the pass information to mail (murthy.doddipatla@gmail.com). Thank you everyone

    ReplyDelete
  12. Hey sir
    I need ur help
    I am working on conversion how i convert image into text plzzz help me
    Mail " sweetbacha22@gmail.com" plzz

    ReplyDelete
  13. why are giving out email, if there is a solution it can be shared openly. it might benefit more people.

    ReplyDelete