1

I'm trying to generate the legend of my mapguide map from the mapguide API but I've found any samples...

Have you an idea of how to use GenerateLegendImage function on a layer and how to convert the MgByteReader result to base64 img string ?

1 Answer 1

1

It's indeed not easy, I've done it myself eventually after a lot of fiddling around. But basically what I did is generate the image with GenerateLegendImage().ToFile() then read that file again and transform that file into a base64 string. And then afterwards clean up the file.

Example:

    mservice.GenerateLegendImage(layerResource, 1, 15, 15, "PNG", geometryType, category).ToFile(filename);
    using (Image img = Image.FromFile(filename))
        {
            using (MemoryStream m = new MemoryStream())
            {
                img.Save(m, img.RawFormat);
                byte[] bytes = m.ToArray();

                string base64 = Convert.ToBase64String(bytes);

                return base64;
            }
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.