Question

I'm working with Scintilla (not ScintillaNET), and I'm trying to set the images used in the auto complete list. Scintilla requires a string of bytes/pixels in the RGBA format.

Scintilla's description of this RGBA format: (Quote from documentation)

The RGBA format allows translucency with an alpha value for each pixel. It is simpler than XPM and more capable.

The data is a sequence of 4 byte pixel values starting with the pixels for the top line, with the leftmost pixel first, then continuing with the pixels for subsequent lines. There is no gap between lines for alignment reasons.

Each pixel consists of, in order, a red byte, a green byte, a blue byte and an alpha byte. The colour bytes are not premultiplied by the alpha value. That is, a fully red pixel that is 25% opaque will be [FF, 00, 00, 3F]

I expect that I'm misunderstanding the format explained above, the documentation is not very clear.

My Conversion Method:

I wrote this function to convert a PNG into this string of bytes:

public static string ConvertFromPNG(Bitmap PNG)
{
    string rgba = "";

    int pixWidth = PNG.Width;
    int pixHeight = PNG.Height;

    for (var y = 0; y < pixHeight; y++)
    {
        for (var x = 0; x < pixWidth; x++)
        {
            Color pix = PNG.GetPixel(x, y);

            rgba += pix.R.ToString("X2") + pix.G.ToString("X2") + pix.B.ToString("X2") + pix.A.ToString("X2");
        }
    }

    return rgba;
}

The Resulting Image:

But Scintilla is just showing the image as a grey box:

Autocomplete box.

The image in question is a copy of one of Microsoft's Babel images: Babel icon.

I know that the set of bytes is correct because interestingly, if I format them in lines and zoom out on them I can see the outline of the image:

Bytes(Zoomed out in image editor)

Bytes Generated:

00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009F000000EC0000001B00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000815B0000DF9B0000F8000000B40000002F000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001B0000007F4E0000FDC80000FFFF0000FF720000FF1D0000B50000003E00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001613000085350000FFDE0000FFFF0000FFFF0000FFFF0000FF750000FF230000C4000000240000000000000000000000000000000000000000000000000000000000000000000000000000000000000085400000EADB0000FFF90000FFFF0000FFFF0000FFFF0000FFF60000FFA70000F5000000DA00000000000000000000000000000000000000000000000000000000000000000000000000000091810000EACA0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFBB0000FF460000FF000000FF000000000000000000000000000000000000000000000000000000000000000000000000000000FF7E0000FFE80000FFFF0000FFFF0000FFFF0000FFFB0000FFB30000FF460000FF0C0000FF000000FF000000000000000000000000000000000000000000000000000000000000000000000000000000FF000000FF660000FFFF0000FFFF0000FFFF0000FFC70000FF0D0000FF590000FF7A0000FF000000FF000000000000000000000000000000000000000000000000000000000000000000000000000000FF8C0000FF7D0000FF2E0000FFFF0000FFBB0000FF1C0000FF510000FFB40000FF7B0000FF000000FF000000000000000000000000000000000000000000000000000000000000000000000000000000FFE20000FFE40000FF410000FF8B0000FF510000FF350000FFB60000FF8F0000FF3A0000EA00000091000000000000000000000000000000000000000000000000000000000000000000000000000000DA910000F5F30000FFFF0000FF0C0000FF270000FFC10000FF930000FF220000EA0000008500000000000000000000000000000000000000000000000000000000000000000000000000000000000000241D0000C4870000FFFF0000FF270000FF420000FF9E0000FF230000FF090000860000001600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003E2D0000B5610000FF120000FF1C0000FF370000FD0000007F0000001B000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002E000000B4000000F8000000DF00000081000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001B000000EC0000009F0000000000000000000000000000000000000000
Was it helpful?

Solution

You are formatting the bytes as hex values and placing them in a string. Scintilla just wants the bytes themselves.

I suspect you want to create a byte array rather than a string, and store into it the values of pix.R, pix.G, pix.B, and pix.A directly, rather than formatting them as strings.

OTHER TIPS

After accepting JasonD's answer I've updated my code and it's working. In case it helps anyone else, here is the working code:

public static byte[] ConvertFromPNG(Bitmap PNG)
{
    byte[] rgbaB = new byte[4 * (PNG.Width * PNG.Height)];

    int i = 0;

    for (var y = 0; y < PNG.Height; y++)
    {
        for (var x = 0; x < PNG.Width; x++)
        {
            Color pix = PNG.GetPixel(x, y);

            rgbaB[i++] = pix.R;
            rgbaB[i++] = pix.G;
            rgbaB[i++] = pix.B;
            rgbaB[i++] = pix.A;
        }
    }

    return rgbaB;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top