Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member182779
Active Contributor
You may wonder that this is a very weird blog...But you know me...I love weird things LOL  What we need first is a Dynpro screen with a Custom Control named *PICTURE* attached to it. LIKE LINE OF graphic_table.  *&---------------------------------------------------------- &* *&      START-OF-SELECTION                                   &* *&---------------------------------------------------------- &* START-OF-SELECTION.   CALL SCREEN 100.  *&---------------------------------------------------------- * *&      Module  STATUS_0100  OUTPUT                          * *&---------------------------------------------------------- * MODULE status_0100 OUTPUT.   PERFORM load_image. ENDMODULE.                 " STATUS_0100  OUTPUT  *----------------------------------------------------------- * *       FORM LOAD_IMAGE                                      * *----------------------------------------------------------- * FORM load_image.    CREATE OBJECT: container1 EXPORTING container_name = 'PICTURE',                  picture EXPORTING parent = container1.    CALL FUNCTION 'SAPSCRIPT_GET_GRAPHIC_BDS'     EXPORTING       i_object       = 'GRAPHICS'       i_name         = 'ENJOY'       i_id           = 'BMAP'       i_btype        = 'BCOL'     IMPORTING       e_bytecount    = l_bytecount     TABLES       content        = l_content     EXCEPTIONS       not_found      = 1       bds_get_failed = 2       bds_no_content = 3       OTHERS         = 4.    CALL FUNCTION 'SAPSCRIPT_CONVERT_BITMAP'     EXPORTING       old_format               = 'BDS'       new_format               = 'BMP'       bitmap_file_bytecount_in = l_bytecount     IMPORTING       bitmap_file_bytecount    = graphic_size     TABLES       bds_bitmap_file          = l_content       bitmap_file              = graphic_table     EXCEPTIONS       OTHERS                   = 1.    DESCRIBE TABLE graphic_table LINES lines.    lines = lines.   w_counter = lines - 1.    read table graphic_table index 1.   move graphic_table-line to graphic_table_new-line.   append graphic_table_new.    DO lines TIMES.     READ TABLE graphic_table INDEX w_counter.     MOVE graphic_table-line TO in_line.     PERFORM reverse_string USING in_line                            CHANGING line.     MOVE line TO graphic_table_new-line.     APPEND graphic_table_new.     CLEAR line.     w_counter = w_counter - 1.   ENDDO.    CALL FUNCTION 'DP_CREATE_URL'     EXPORTING       type    = 'IMAGE'       subtype = 'BMP'     TABLES       data    = graphic_table_new     CHANGING       url     = url.    CALL METHOD picture->load_picture_from_url     EXPORTING       url = url.   CALL METHOD picture->set_display_mode     EXPORTING       display_mode = picture->display_mode_fit_center.  ENDFORM.                    "LOAD_IMAGE  *----------------------------------------------------------- * *      Form  REVERSE_STRING                                  * *----------------------------------------------------------- * FORM reverse_string USING p_line CHANGING p_outline.    DATA: long TYPE i,         w_counter TYPE i.    long = STRLEN( p_line ).   w_counter = long - 1.    DO long TIMES.     CONCATENATE p_outline p_line+w_counter(1)     INTO p_outline.     w_counter = w_counter - 1.   ENDDO.  ENDFORM.                    "REVERSE_STRING   If you run this program, without doing any harm to the original picture...Your going to get this...If you harm the image, your going to end with this...As you can see...I actually could reverse the image...But the color looks like a mess...So...Can you fix this? Can you improve the program to get new image filters? Sounds like a little challenge to me -:)  *--------------------------------------- UPDATE--------------------------------------- *    I recieved a mail from one of my SDN heroes Mr. Thomas Jung  (https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=5%...) a couple of days ago...Thomas took my challenge and showed me that I was completely wrong...Image processing can be done in ABAP...He kindly send me this awesome code... LIKE LINE OF graphic_table.  *&---------------------------------------------------------- &* *&      START-OF-SELECTION                                   &* *&---------------------------------------------------------- &* START-OF-SELECTION.   CALL SCREEN 100.  *&---------------------------------------------------------- * *&      Module  STATUS_0100  OUTPUT                          * *&---------------------------------------------------------- * MODULE status_0100 OUTPUT.   PERFORM load_image. ENDMODULE.                 " STATUS_0100  OUTPUT  *----------------------------------------------------------- * *       FORM LOAD_IMAGE                                      * *----------------------------------------------------------- * FORM load_image.    CREATE  OBJECT: container1 EXPORTING  container_name = 'PICTURE' ,                    picture EXPORTING  parent = container1.    CALL FUNCTION 'SAPSCRIPT_GET_GRAPHIC_BDS'     EXPORTING       i_object       = 'GRAPHICS'       i_name         = 'ENJOY'       i_id           = 'BMAP'       i_btype        = 'BCOL'     IMPORTING       e_bytecount    = l_bytecount     TABLES       content        = l_content     EXCEPTIONS       not_found      = 1       bds_get_failed = 2       bds_no_content = 3       OTHERS         = 4.    CALL FUNCTION 'SAPSCRIPT_CONVERT_BITMAP'     EXPORTING       old_format               = 'BDS'       new_format               = 'BMP'       bitmap_file_bytecount_in = l_bytecount     IMPORTING       bitmap_file_bytecount    = graphic_size     TABLES       bds_bitmap_file          = l_content       bitmap_file              = graphic_table     EXCEPTIONS       OTHERS                   = 1.    DESCRIBE TABLE graphic_table LINES lines.    lines  = lines.   w_counter = lines  - 1.   DATA  x_bmp TYPE  xstring.   CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'     EXPORTING       input_length = graphic_size     IMPORTING       buffer       = x_bmp     TABLES       binary_tab   = graphic_table     EXCEPTIONS       failed       = 1       OTHERS       = 2.    DATA : w2(2) TYPE  x , w4(4) TYPE  x , xstr TYPE  xstring.   DEFINE  read2.  "#EC NEEDED read two bytes as integer and move offset     w2 = &1.     concatenate  w2+1(1) w2+0(1) into  xstr in  byte mode .     &2 = xstr.   END-OF-DEFINITION .    DEFINE  read4. "#EC NEEDED read four bytes as integer and move offset     w4 = &1 .     concatenate  w4+3(1) w4+2(1) w4+1(1) w4+0(1) into  xstr in  byte mode .     &2 = xstr.   END-OF-DEFINITION .    DATA  magic_number(2) TYPE x.   magic_number = x_bmp+0(2).   DATA size(4) TYPE  x.   DATA i_size TYPE  i.   size = x_bmp+2(4).   DATA data_offset(4) TYPE x.   DATA i_data_offset TYPE i.   data_offset = x_bmp+10(4).   read4 size i_size.   read4 data_offset i_data_offset.    DATA  header_size(4) TYPE x.   DATA  i_header_size TYPE i.   header_size = x_bmp+14(4).   read4 header_size i_header_size.    DATA : width(4) TYPE  x,         height(4) TYPE  x,         i_width TYPE  i,         i_height TYPE i,         bpp(2) TYPE x,         i_bpp TYPE i,         compression(4) TYPE x,         i_compression TYPE i,         s_compression TYPE string.    IF  i_header_size = 40. "Windows V3 Format     width = x_bmp+18(4).     height = x_bmp+22(4).     bpp = x_bmp+28(2).     compression = x_bmp+30(4).     read4 width i_width.     read4 height i_height.     read2 bpp i_bpp.     read4 compression i_compression.   ENDIF.   CASE  i_compression.     WHEN  0.       s_compression = 'RGB - None'.     WHEN  1.       s_compression = 'RLE 8-bit/pixel'.     WHEN  2.       s_compression = 'RLE 4-bit/pixel'.     WHEN  3.       s_compression = 'Bit Field'.     WHEN  4.       s_compression = 'JPEG'.     WHEN  5.       s_compression = 'PNG'.   ENDCASE.    DATA x_data TYPE xstring.   DATA x_new_data TYPE xstring.   DATA i_num_pixels TYPE i.   DATA i_counter TYPE i.   DATA i_counter2 TYPE i.    x_data = x_bmp+i_data_offset. *  i_num_pixels = XSTRLEN( x_data ).   i_num_pixels = i_width. "i_num_pixels / 3 / i_height.   DATA  i_width_in_bytes TYPE  i.   i_width_in_bytes = i_width * 3.    DATA  x_row TYPE  xstring.   DATA  x_new_row TYPE  xstring.   DO  i_height TIMES.     x_row = x_data+i_counter(i_width).     CLEAR  i_counter2.     CLEAR  x_new_row.     DO  i_num_pixels TIMES .       CONCATENATE  x_row+i_counter2(1) x_new_row INTO x_new_row IN BYTE MODE.       i_counter2 = i_counter2 + 1.     ENDDO .     CONCATENATE  x_new_row x_new_data INTO  x_new_data IN BYTE MODE.     i_counter = i_counter + i_width.   ENDDO .    DATA  x_new_image TYPE  xstring.   CONCATENATE x_bmp(i_data_offset) x_new_data INTO x_new_image IN BYTE MODE.    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'     EXPORTING       buffer     = x_new_image     TABLES       binary_tab = graphic_table_new.    CALL FUNCTION 'DP_CREATE_URL'     EXPORTING       type    = 'IMAGE'       subtype = 'BMP'     TABLES       data    = graphic_table_new     CHANGING       url     = url.    CALL METHOD picture->load_picture_from_url     EXPORTING       url = url.   CALL METHOD picture->set_display_mode     EXPORTING       display_mode = picture->display_mode_normal.  ENDFORM.                    "LOAD_IMAGE    We're going to see this picture as the result...
12 Comments