1

I am working on an MFC app that uses CDHtmlDialog class to create a dynamic HTML page.

Now i want to pass/stream a image pointer to the HTML page to show it to the users.

The image will be stored in the hard disk, and the MFC should have a way of streaming this to the HTML page for display on a particular user event.

I am not sure how to convert a JPG or GIF file into something else that i can pass to the HTML page.

Possibly as an argument to JavaScript function residing in the HTML page.

Any help is welcome. Please guide with sample codes.

Thanks in advance.

Dipu KS
  • 63
  • 7

1 Answers1

0

Firstly, refer to How to display Base64 images in HTML?. Then encode the image data using the following function. Hope this help!

    string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
    string ret;
    int i = 0;
    int j = 0;
    unsigned char char_array_3[3];
    unsigned char char_array_4[4];

    while (in_len--) {
        char_array_3[i++] = *(bytes_to_encode++);
        if (i == 3) {
            char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
            char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
            char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
            char_array_4[3] = char_array_3[2] & 0x3f;

            for (i = 0; (i <4); i++)
                ret += base64_chars[char_array_4[i]];
            i = 0;
        }
    }

    if (i)
    {
        for (j = i; j < 3; j++)
            char_array_3[j] = '\0';

        char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
        char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
        char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);

        for (j = 0; (j < i + 1); j++)
            ret += base64_chars[char_array_4[j]];

        while ((i++ < 3))
            ret += '=';
    }

    return ret;
}
Miller Cy Chan
  • 897
  • 9
  • 19