1. 程式人生 > >顯示圖片方法

顯示圖片方法

其實主要就是個呼叫類的方法,但是實現還是要通過TCODE SMW0 來上傳圖片才可以的。
接下來的東西用那個方法就可以實現,定義大小滿足要求就好。

可以通過使用類cl_gui_picture載入picture.

一些方法:
data picture type ref to cl_gui_picture.

構造方法
CREATE OBJECT picture "
建立picture物件
    EXPORTING lifetime   = lifetime
               shellstyle = shellstyle
               parent     = parent
    EXCEPTIONS ERROR = 1.

通過url載入照片:
CALL METHOD picture->load_picture_from_url
        EXPORTING url = url
        IMPORTING result = result
        EXCEPTIONS error = 1.

設定顯示模式:
CALL METHOD picture->set_display_mode
           EXPORTING display_mode = display_mode
           EXCEPTIONS error = 1.
display_mode:
picture->display_mode_stretch
picture->display_mode_fit
picture->display_mode_normal
picture->display_mode_fit_center
picture->display_mode_normal_center

載入ICON
CALL METHOD picture->load_picture_from_sap_icons
            EXPORTING icon = icon
            EXCEPTIONS error = 1.

icon
sap icon的名稱後者是'@[email protected]'形式
顯示右鍵上下文:
CALL METHOD picture->display_context_menu
          exporting context_menu = context_menu
          exceptions error = 1.

===========================================================================
如何從BOR中載入圖片資料:

方法一:call function 'DP_PUBLISH_WWW_URL',根據OBJID獲得URL.
再通過URL載入圖片
CALL FUNCTION 'DP_PUBLISH_WWW_URL'
EXPORTING
    OBJID                       = 'HTMLCNTL_TESTHTM2_SAP_AG'
    LIFETIME                    = cndp_lifetime_transaction
IMPORTING
    URL                         = url
EXCEPTIONS
    OTHERS                      = 1.

CALL METHOD PICTURE_CONTROL_1->LOAD_PICTURE_FROM_URL_async
         exporting url = url.

方法二:
data query_table like w3query occurs 1 with header line.
data query_html like w3html occurs 1.
data return_code like w3param-ret_code.
data content_type like w3param-cont_type.
data content_lenght like w3param-cont_len.
data pic_data like w3mime occurs 0.
data pic_size type i.
call function 'WWW_GET_MIME_OBJECT'
tables
query_string = query_table
html = html_table
mime = pic_data
changing
reuturn_code = return_code
content_type = content_type
content_length = content_length.
pic_size = content_length
call function 'DP_CREATE_URL'
exporting
type = 'image'
subtype = cndp_sap_tab_unknown
size = pic_size
lifetime = cndp_lifetime_transaction
tables
data = pic_data
changing
url = url.

CALL METHOD picture->load_picture_from_url"最後還是根據picture->load_picture_from_url
        EXPORTING url = url.


方法三:載入ICON
CALL METHOD picture->load_picture_from_sap_icons
            EXPORTING icon = '@[email protected]'
            EXCEPTIONS error = 1.

 
以上是朋友轉貼得來: