Re: convert string base64Binary to byte[]
On Mar 13, 12:21 pm, MrAsm <m...@usa.com> wrote:
On 13 Mar 2007 08:45:06 -0700, dom_per...@hotmail.com wrote:
Hi,
I have a bitmap stored in a XML document in binary (base64Binary ). I
need to convert this data to byte[] for creating the CBitmap. Here is
[...]
io_rBitmap.SetBitmapBits((DWORD)sizeof(bytes), &bytes);
delete[] bytes;
The image generated is black... Do I have to convert my string in byte
before?
Yes.
You must *decode* the Base64 sequence.
If yes, how can I do this?
You might want to reuse some already written Base64 decoding stuff,
e.g.:
http://www.fourmilab.ch/webtools/base64/http://www.codeproject.com/string/ammimeutils.asphttp://www.codeproject.com/internet/mimecpp.asp
MrAsm
Hi,
Thanks to have answered me so quickly.
Perhaps I miss something but I tried what you suggested to me but I
always have the black image...
strBinImage =
"R0lGODlhOQAwAPUAAAAAAKBggOCgwIAAAMBggMDAwKBAAMCggKDAwMCgwEBAgKCgpP/..."
//Decode from base64
CBase64Utils decoder;
int lenght = strBinImage.GetLength();
CString strDecoded = decoder.Decode((char*)strBinImage.GetString(),
&lenght);
BYTE* bytes = new BYTE[strDecoded.GetLength()];
for (int i = 0; i < strDecoded.GetLength(); i++)
{
bytes[i] = (BYTE)strDecoded.GetAt(i);
}
io_rBitmap.SetBitmapBits((DWORD)sizeof(bytes), &bytes);
delete[] bytes;