[ABAP] Bilddatei konvertieren mit Hilfe der Klasse cl_igs_image_converter (Internet Graphics Service: Image Converter)

* Dateiname der Bilddatei zum hochladen
PARAMETERS: p_fname TYPE file_table-filename OBLIGATORY.

* wenn die F4-Hilfe für den Dateinamen aufgerufen wird
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.

  DATA: lv_rc TYPE i.
  DATA: it_files TYPE filetable.
  DATA: lv_action TYPE i.

* File-Tabelle leeren, da hier noch alte Einträge von vorherigen Aufrufen drin stehen können
  CLEAR it_files.

* FileOpen-Dialog aufrufen
  TRY.
      cl_gui_frontend_services=>file_open_dialog( EXPORTING
                                                    file_filter = |gif (*.gif)\|*.gif\|{ cl_gui_frontend_services=>filetype_all }|
                                                  CHANGING
                                                    file_table  = it_files
                                                    rc          = lv_rc
                                                    user_action = lv_action ).

      IF lv_action = cl_gui_frontend_services=>action_ok.
* wenn Datei ausgewählt wurde
        IF lines( it_files ) > 0.
* ersten Tabelleneintrag lesen
          p_fname = it_files[ 1 ]-filename.
        ENDIF.
      ENDIF.

    CATCH cx_root INTO DATA(e_text).
      MESSAGE e_text->get_text( ) TYPE 'S' DISPLAY LIKE 'E'.
  ENDTRY.

START-OF-SELECTION.
  DATA: lv_filesize TYPE w3param-cont_len.
  DATA: lv_filetype TYPE w3param-cont_type.
  DATA: it_bin_data TYPE w3mimetabtype.

* Bild auf Appl. Server hochladen (binary)
  cl_gui_frontend_services=>gui_upload( EXPORTING
                                          filename = |{ p_fname }|
                                          filetype = 'BIN'
                                        IMPORTING
                                          filelength = lv_filesize
                                        CHANGING
                                          data_tab = it_bin_data ).

* Konverterobjekt erzeugen
  DATA(o_conv) = NEW cl_igs_image_converter( ).
  o_conv->input = 'image/gif'.       " Quellformat ist ein GIF
  o_conv->output = 'image/x-ms-bmp'. " Ausgabeformat ist ein BMP
*  o_conv->height = '100'. " neue Höhe 100
*  o_conv->width = '100'.  " neue Breite 100

* Bildaten übergeben
  o_conv->set_image( blob = it_bin_data
                     blob_size = lv_filesize ).

* Image konvertieren
  o_conv->execute( ).

* Anzahl Ergebnisbilder -> 0
  IF o_conv->get_image_count( ) -> 0.
* Bilddaten im Ausgabeformat holen
    o_conv->get_image( IMPORTING
                         blob = it_bin_data
                         blob_size = lv_filesize
                         blob_type = lv_filetype ).

* Image lokal speichern
    cl_gui_frontend_services=>gui_download(
          EXPORTING
            filename                = 'c:\temp\temp.bmp'
            filetype                = 'BIN'
          CHANGING
            data_tab                = it_bin_data ).
  ENDIF.

[ABAP] Verwendung des Engineering Client Viewer für 2D-/3D-Objekte (ECL viewer)

Beispiel 1: JPEG anzeigen

DATA: o_dock TYPE REF TO cl_gui_docking_container.

PARAMETERS: p_name TYPE string. " Dummy-Parameter

AT SELECTION-SCREEN OUTPUT.

  IF NOT o_dock IS BOUND.
* Dockingcontainer erzeugen
    o_dock = NEW #( repid = sy-repid
                    dynnr = sy-dynnr
                    side  = cl_gui_docking_container=>dock_at_right
                    ratio = 50 ).

* ECL viewer erzeugen
    DATA(o_viewer) = NEW cl_gui_ecl_2dviewer( parent = o_dock ).

* Toolbar einstellen
    o_viewer->create_toolbar( close_button = abap_false
                              navigation = abap_true
                              options = abap_true
                              remove_document = abap_true
                              tools = abap_false
                              tool_stamp = abap_false
                              tool_compare = abap_false
                              tool_measurement = abap_false
                              viewer = abap_true
                              viewer_openfile = abap_true
                              viewer_savefile = abap_true
                              viewer_closefile = abap_true ).

* JPEG anzeigen
    o_viewer->open_document( file = 'c:\temp\temp.jpg'
                             file_type = 'image/jpeg' ). " https://wiki.selfhtml.org/wiki/Referenz:MIME-Typen

  ENDIF.

Beispiel 2: PDF anzeigen

  
* ECL viewer in extra Fenster
DATA(o_viewer) = NEW cl_gui_ecl_viewerbox( ).

* Fullscreen
o_viewer->set_alignment( alignment = cl_gui_control=>align_at_left + cl_gui_control=>align_at_right + cl_gui_control=>align_at_top + cl_gui_control=>align_at_bottom ).

* PDF öffnen
o_viewer->open_document( file = 'c:\temp\temp.pdf'
                         file_type = 'application/pdf' ). " https://wiki.selfhtml.org/wiki/Referenz:MIME-Typen

Weiterführende Infos:

[ABAP] Bild (JPEG) aus dem MIME-Repository laden und anzeigen

* Demo-Programm: SAP_PICTURE_DEMO
DATA: o_dock TYPE REF TO cl_gui_docking_container.

PARAMETERS: p_name TYPE string. " Dummy-Parameter

AT SELECTION-SCREEN OUTPUT.

  IF NOT o_dock IS BOUND.
* Dockingcontainer erzeugen
    o_dock = NEW #( repid = sy-repid
                    dynnr = sy-dynnr
                    side  = cl_gui_docking_container=>dock_at_right
                    ratio = 50 ).

    DATA: lv_xstr TYPE xstring.

* MIME-API holen
    DATA(o_mime_rep) = cl_mime_repository_api=>get_api( ).

* Bild aus dem MIME-Repository laden
    o_mime_rep->get( EXPORTING
                       i_url = '/SAP/PUBLIC/Test123.jpg'
                       i_check_authority = abap_false
                     IMPORTING
                       e_content = lv_xstr ).

    DATA: it_bin_data TYPE STANDARD TABLE OF raw255.

* xstring nach binary (RAW) wandeln
    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
      EXPORTING
        buffer     = lv_xstr
      TABLES
        binary_tab = it_bin_data.

    DATA: lv_url TYPE char255.

* temporäre URL auf das Bild erzeugen
    CALL FUNCTION 'DP_CREATE_URL'
      EXPORTING
        type                 = 'image/jpeg' " https://wiki.selfhtml.org/wiki/Referenz:MIME-Typen
        subtype              = 'jpg'
      TABLES
        data                 = it_bin_data
      CHANGING
        url                  = lv_url
      EXCEPTIONS
        dp_invalid_parameter = 1
        dp_error_put_table   = 2
        dp_error_general     = 3
        OTHERS               = 4.

* Bild über die URL laden und anzeigen
    DATA(o_pic) = NEW cl_gui_picture( parent = o_dock ).
    o_pic->set_display_mode( display_mode = cl_gui_picture=>display_mode_fit_center ).
    o_pic->load_picture_from_url_async( lv_url ).
  ENDIF.

Weiterführende Infos: Link

[ABAP] Bild (JPEG) vom lokalen Rechner ins MIME-Repository hochladen

* Dateiname der Bilddatei zum hochladen
PARAMETERS: p_fname TYPE file_table-filename OBLIGATORY.
* Speicherpfad im MIME-Repository, muss vorhanden sein, andernfalls mit o_mime_rep->create_folder( ) erzeugen
PARAMETERS: p_mpath TYPE string DEFAULT '/SAP/PUBLIC/Test123.jpg' OBLIGATORY.

* wenn die F4-Hilfe für den Dateinamen aufgerufen wird
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.

  DATA: lv_rc TYPE i.
  DATA: it_files TYPE filetable.
  DATA: lv_action TYPE i.

* File-Tabelle leeren, da hier noch alte Einträge von vorherigen Aufrufen drin stehen können
  CLEAR it_files.

* FileOpen-Dialog aufrufen
  TRY.
      cl_gui_frontend_services=>file_open_dialog( EXPORTING
                                                    file_filter = |jpg (*.jpg)\|*.jpg\|{ cl_gui_frontend_services=>filetype_all }|
                                                  CHANGING
                                                    file_table  = it_files
                                                    rc          = lv_rc
                                                    user_action = lv_action ).

      IF lv_action = cl_gui_frontend_services=>action_ok.
* wenn Datei ausgewählt wurde
        IF lines( it_files ) > 0.
* ersten Tabelleneintrag lesen
          p_fname = it_files[ 1 ]-filename.
        ENDIF.
      ENDIF.

    CATCH cx_root INTO DATA(e_text).
      MESSAGE e_text->get_text( ) TYPE 'S' DISPLAY LIKE 'E'.
  ENDTRY.

START-OF-SELECTION.
  DATA: lv_filesize TYPE i.
  DATA: it_bin_data TYPE STANDARD TABLE OF raw255.

* Bild auf Appl. Server hochladen (binary)
  cl_gui_frontend_services=>gui_upload( EXPORTING
                                          filename = |{ p_fname }|
                                          filetype = 'BIN'
                                        IMPORTING
                                          filelength = lv_filesize
                                        CHANGING
                                          data_tab = it_bin_data ).

  DATA: lv_xstr TYPE xstring.

* RAW (binary) nach xstring
  CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
    EXPORTING
      input_length = lv_filesize
    IMPORTING
      buffer       = lv_xstr
    TABLES
      binary_tab   = it_bin_data
    EXCEPTIONS
      failed       = 1
      OTHERS       = 2.

* MIME-API holen
  DATA(o_mime_rep) = cl_mime_repository_api=>get_api( ).

* Bild im MIME-Repository speichern
* Objektkatalogeintrag wird erstellt, evtl. bestehende Dateien werden überschrieben
  o_mime_rep->put( i_url = p_mpath
                   i_content = lv_xstr
                   i_check_authority = abap_false ).

[ABAP] MIME-Objekt aus dem Repository laden

* Objekt-ID des Mime-Objekts
DATA: lv_object_id TYPE char32 VALUE 'EE3ECB43B3E70B43E10000000A15509A'.

DATA: lv_desc TYPE skwf_desc.
DATA: lv_docname TYPE skwf_urlp.
DATA: lv_filename TYPE string.
DATA: lv_filesize TYPE i.
DATA: lv_mimetype TYPE mr_mimtype.
DATA: lv_langu TYPE sy-langu.

DATA: it_bin_data TYPE sdokcntbins. " RAW1022

DATA(lv_io) = VALUE skwf_io( objtype = 'L' " Unbestimmt (= alle), F Verzeichnis, L Loio, P Phio, R Relation
                             class = 'M_IMAGE_L'
                             objid = lv_object_id ).

* Sprachvorgabe
lv_langu = 'D'.

* MIME-Objekt laden
cl_wb_mime_repository=>load_mime( EXPORTING
                                    io              = lv_io
                                  IMPORTING
                                    docname         = lv_docname
                                    description     = lv_desc
                                    filename        = lv_filename
                                    filesize        = lv_filesize
                                    bin_data        = it_bin_data
                                    mimetype        = lv_mimetype
                                  CHANGING
                                    language        = lv_langu ).

WRITE: / lv_docname.
WRITE: / lv_desc.
WRITE: / lv_filename.
WRITE: / lv_filesize.
WRITE: / lv_mimetype.
WRITE: / lv_langu.

DATA: lv_xstr_line TYPE xstring.
DATA: lv_xstr_result TYPE xstring.

* RAW (binary) -> xstring
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
  EXPORTING
    input_length = lv_filesize
  IMPORTING
    buffer       = lv_xstr_result
  TABLES
    binary_tab   = it_bin_data
  EXCEPTIONS
    failed       = 1
    OTHERS       = 2.

IF sy-subrc NE 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.