Freigeben über


HOWTO: Dynamicaly load picture from base64 string into image on form in X++

You may want to load an image from base64 coded string. Then there is a code sample how to achieve it. First is needed to put an "Window" controll on the form with name ex. "imageWindow" and then modify "run()" method of Form. String then could be loaded from database, generated by .NET (for example dynamicaly generate picture) etc.

 public void run()
{
    container                           baseContainer;
    BinData                             binData;
    Image                               img;

    ;
    super();

    // create container from base64
    baseContainer =  BinData::loadFromBase64(".... BASE64 STRING....");
    
    // create bindata from container.
    binData = new BinData();
    binData.setData(baseContainer);

    // lock element
    element.lock();

    // create Image from bindata
    img = new Image();
    img.setData(binData.getData());

    // show and update image.
    imageWindow.image(img);
    imageWindow.widthValue(img.width());
    imageWindow.heightValue(img.height());
    imageWindow.update();

    // unlock elements.
    element.resetSize();
    element.unLock();
}

Karel F

Comments