C# - High Quality Byte Array Conversion of Images

Posted by Lijo on Stack Overflow See other posts from Stack Overflow or by Lijo
Published on 2010-06-17T20:01:00Z Indexed on 2010/06/17 20:03 UTC
Read the original article Hit count: 183

Filed under:

Hi Team,

I am converting images to byte array and storing in a text file using the following code. I am retrieving them successfully as well.

My concern is that the quality of the retrieved image is not up to the expectation. Is there a way to have better conversion to byte array and retrieving? I am not worried about the space conception.

Please share your thoughts.

    string plaintextStoringLocation = @"D:\ImageSource\Cha5.txt";
    string bmpSourceLocation = @"D:\ImageSource\Cha50.bmp";

    ////Read image
    Image sourceImg = Image.FromFile(bmpSourceLocation);

    ////Convert to Byte[]
    byte[] clearByteArray = ImageToByteArray(sourceImg);


    ////Store it for future use (in plain text form)
    StoreToLocation(clearByteArray, plaintextStoringLocation);

    //Read from binary
    byte[] retirevedImageBytes = ReadByteArrayFromFile(plaintextStoringLocation);

    //Retrieve from Byte[]
    Image destinationImg = ByteArrayToImage(retirevedImageBytes);

    //Display Image
    pictureBox1.Image = destinationImg;

Thanks

Lijo

© Stack Overflow or respective owner

Related posts about c#