¡Caminando hacia el éxito!

Aprende en Comunidad

Avalados por :

Cómo codificar una imagen en base64 y mostrarla en un contenedor HTML

  • Creado 01/03/2024
  • Modificado 01/03/2024
  • 70 Vistas
0
Cargando...
Today I stumbled upon an old test report where I tried to display a base64 encoded picture in a container.

This is how it looks




This is how it works


BASE64 encoding is a method to store binary data with codepage independent readable ASCII characters. Readable characters can be stored in an ABAP report which makes it possible to store a picture in a source code.

To encode a picture to BASE64 you will need to have a converter. There are many converters online available, e.g. this one: https://www.base64encode.net/base64-image-encoder

For demonstration I used a very small picture. I found one in the 8-bit-retro-Excel-racing-simulation galoppsim by marco.krapf in the last Galoppsim corona cup . If you do not know Galoppsim.racing so far, I recommend to visit https://galoppsim.racing/ as soon as possible,

I chose Rennpony as suitable candidate for my demonstration. Even though the marvelous graphics are in 8bit-mode I still had to convert them to a very small size. The displayed picture has a size of 21x19 pixels.

So I uploaded the small graphic to the base64-encoding website and got the following string:
R0lGODlhFQATADMAACH5BAAAAAAALAAAAAAVABMAg////19qcHaPjo6ij5XL/p3Mx6rR3
qTS+LPUksPessjcysvl+ufbrvrclPfv1Or0+wSMEMg5F1mY6g0eztzmNA3TKEu4LYaptI
2jShbBMIahlDNwXCwDYcdQeQ6HwEDxOyiKmyNhKhj8pobYBjkl6K5TokZRKBe+3enhRnE
g3u/EbwH2aiWJfB6hfjzAa3d6ewYHDzRpWQ0SCoMJBoc0gCYOMo15hho1aiaLAAqgkRR/
aYE9iKVQPZtppwCsXREAOw==

This string has to be decoded into an xstring.

The xstring has to be converted to an xstring table.

This xstring table can be passed to function module DP_CREATE_URL which returns a pointer (url) to these bytes. It then can be used in CL_GUI_PICTURE control to display the data.

The code


REPORT.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    TYPES _url TYPE c LENGTH 200.
    TYPES: BEGIN OF _graphic_row,
             line(255) TYPE x,
           END OF _graphic_row,
           _graphic_tab TYPE STANDARD TABLE OF _graphic_row WITH DEFAULT KEY.
    METHODS show.
  PRIVATE SECTION.
    METHODS get_image_url
      RETURNING
        VALUE(url) TYPE url.
    METHODS convert_xstring_to_table
      
                
                
Pedro Pascal
Se unió el 07/03/2018
Pinterest
Telegram
Linkedin
Whatsapp

Sin respuestas

No hay respuestas para mostrar No hay respuestas para mostrar Se el primero en responder

contacto@primeinstitute.com

(+51) 1641 9379
(+57) 1489 6964

© 2024 Copyright. Todos los derechos reservados.

Desarrollado por Prime Institute

¡Hola! Soy Diana, asesora académica de Prime Institute, indícame en que curso estas interesado, saludos!
Hola ¿Puedo ayudarte?