Конвертация и модификация изображений
Программа конвертации PNG в JPEG с изменением размеров.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
PARAMETERS: p_fname TYPE file_table-filename OBLIGATORY. PARAMETERS: p_width TYPE i DEFAULT 800. PARAMETERS: p_height TYPE i DEFAULT 600. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname. DATA: lv_rc TYPE i. DATA: it_files TYPE filetable. DATA: lv_action TYPE i. CLEAR it_files. 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. IF lines( it_files ) > 0. 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. cl_gui_frontend_services=>gui_upload( EXPORTING filename = |{ p_fname }| filetype = 'BIN' IMPORTING filelength = lv_filesize CHANGING data_tab = it_bin_data ). DATA(lv_img_data) = cl_bcs_convert=>solix_to_xstring( it_solix = it_bin_data ). DATA(o_ip) = NEW cl_fxs_image_processor( ). 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. 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 ). 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. o_ip->resize( EXPORTING iv_handle = lv_hndl iv_xres = p_width iv_yres = p_height ). o_ip->convert( EXPORTING iv_handle = lv_hndl iv_format = cl_fxs_mime_types=>co_image_jpeg ). 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 ). 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. DATA(lv_img_conv_data) = o_ip->get_image( EXPORTING iv_handle = lv_hndl ). DATA(it_img_conv_data) = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_img_conv_data ). WRITE: / |{ p_fname }.jpg|. 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. |