* Im Beispiel wird das Eingabebild (PNG) nach JPG konvertiert und auf 800x600px in der Größe verändert
* Dateiname der Bilddatei zum hochladen
PARAMETERS: p_fname TYPE file_table-filename OBLIGATORY.
PARAMETERS: p_width TYPE i DEFAULT 800.
PARAMETERS: p_height TYPE i DEFAULT 600.
* 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 = |png (*.png)\|*.png\|{ 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.
TRY.
DATA: lv_filesize TYPE w3param-cont_len.
DATA: lv_filetype TYPE w3param-cont_type.
DATA: it_bin_data TYPE w3mimetabtype.
WRITE: / p_fname.
* 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 ).
* solix -> xstring
DATA(lv_img_data) = cl_bcs_convert=>solix_to_xstring( it_solix = it_bin_data ).
* FXS-Objekt holen
DATA(o_ip) = NEW cl_fxs_image_processor( ).
* Bild zum Konverter hinzufügen
DATA(lv_hndl) = o_ip->add_image( iv_data = lv_img_data ).
DATA: lv_mimetype TYPE string.
DATA: lv_xres TYPE i.
DATA: lv_yres TYPE i.
DATA: lv_xdpi TYPE i.
DATA: lv_ydpi TYPE i.
DATA: lv_bitdepth TYPE i.
* Infos holen
o_ip->get_info( EXPORTING
iv_handle = lv_hndl
IMPORTING
ev_mimetype = lv_mimetype
ev_xres = lv_xres
ev_yres = lv_yres
ev_xdpi = lv_xdpi
ev_ydpi = lv_ydpi
ev_bitdepth = lv_bitdepth ).
* Infos ausgeben
WRITE: / 'MIME-Type:', lv_mimetype.
WRITE: / ' X:', lv_xres.
WRITE: / ' Y:', lv_yres.
WRITE: / ' X-DPI:', lv_xdpi.
WRITE: / ' Y-DPI:', lv_ydpi.
WRITE: / ' Bit:', lv_bitdepth.
* Größe ändern (Resize)
o_ip->resize( EXPORTING
iv_handle = lv_hndl
iv_xres = p_width
iv_yres = p_height ).
* Konvertierung (Convert) nach JPG
* Zielformate können nur sein (andernfalls gibt es eine Exception vom Typ cx_sy_range_out_of_bounds):
* cl_fxs_mime_types=>co_image_bitmap
* cl_fxs_mime_types=>co_image_png
* cl_fxs_mime_types=>co_image_jpeg
o_ip->convert( EXPORTING
iv_handle = lv_hndl
iv_format = cl_fxs_mime_types=>co_image_jpeg ).
* Infos holen
o_ip->get_info( EXPORTING
iv_handle = lv_hndl
IMPORTING
ev_mimetype = lv_mimetype
ev_xres = lv_xres
ev_yres = lv_yres
ev_xdpi = lv_xdpi
ev_ydpi = lv_ydpi
ev_bitdepth = lv_bitdepth ).
* Infos ausgeben
WRITE: / 'MIME-Type:', lv_mimetype.
WRITE: / ' X:', lv_xres.
WRITE: / ' Y:', lv_yres.
WRITE: / ' X-DPI:', lv_xdpi.
WRITE: / ' Y-DPI:', lv_ydpi.
WRITE: / ' Bit:', lv_bitdepth.
* Binärdaten (xstring) des Bildes holen
DATA(lv_img_conv_data) = o_ip->get_image( EXPORTING iv_handle = lv_hndl ).
* xstring -> solix
DATA(it_img_conv_data) = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_img_conv_data ).
WRITE: / |{ p_fname }.jpg|.
* Image lokal speichern
cl_gui_frontend_services=>gui_download( EXPORTING
filename = |{ p_fname }.jpg|
filetype = 'BIN'
bin_filesize = xstrlen( lv_img_conv_data )
CHANGING
data_tab = it_img_conv_data ).
CATCH cx_root INTO DATA(e_txt).
WRITE: / e_txt->get_text( ).
ENDTRY.