Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The issue is that the conversion between the hex-encoded string to byte array isn't being done property.</p> <p>The code you listed will treat each of the chars in the blob as a byte, so an 'F' will be treated as 0x46 (the ascii code for a capital F). What you want to do is de-code each 2 characters as a single byte - i.e. F0 = 240 etc.</p> <p>It assumes the string is an even number of characters. You'll also need to strip off the '0x' prefix, as that's just an indicator that what follows is a hexadecimal representation of the data.</p> <p>So instead of this:</p> <pre><code>strPhoto = csvuser.photo; // The string that represents the BLOB byte[] bytes = new byte[strPhoto.Length * sizeof(char)]; System.Buffer.BlockCopy(strPhoto.ToCharArray(), 0, bytes, 0, bytes.Length); </code></pre> <p>Do something like this (adapted from previous answer given <a href="https://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa">here</a>):</p> <pre><code> strPhoto = csvuser.photo; // The string that represents the BLOB //remove first 2 chars (the '0x') strPhoto = strPhoto.Remove(0, 2); //convert hex-string to bytes: int NumberChars = strPhoto.Length/2; byte[] bytes = new byte[NumberChars]; using (StringReader sr = new StringReader(strPhoto)){ for (int i = 0; i &lt; NumberChars; i++) bytes[i] = Convert.ToByte(new string(new char[2]{(char)sr.Read(), (char)sr.Read()}), 16); } // Then we create a memory stream that holds the image MemoryStream photostream = new MemoryStream( bytes ); // Then we can create a System.Drawing.Image by using the Memory stream var photo = Image.FromStream(photostream); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload