Image Conversion in .NET

Image Conversion in .NET

Reading binary data from an image

sample code:

string path = “C:\\img1.jpg”;

FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read);

byte[] b = new byte[fs.Length];

fs.Read(b, 0, b.Length);

fs.Close();

Converting the binary data from Bytes to String

sample code:

string str = Convert.ToBase64String(b);

Converting the String back to an Image 

sample code:

MemoryStream ms = new MemoryStream();

Image img11;

byte[] b1;

b1 = Convert.FromBase64String(str);

ms = new System.IO.MemoryStream(b1);

img11 = System.Drawing.Image.FromStream(ms);

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.