Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Convert OTF to Bitmap

0 Kudos

Hi All

How to convert OTF data to Bitmap. Already searched in SCN and there is no thread with complete solution.

Basically, i am using program sapmssco to convert barcode data to OTF but unable to download to .bmp or .jpg or any image extension.

In the program, we have bitmap data but if i download this bitmap data to desktop and when opening the file, it gives error "This is not a valid bitmap file, or its format is not currently supported".

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor

Okay now I'm sure it's possible to do it! (owing to Juwin findings)

REPORT.
PARAMETERS: barcode like tfo05-tdbarcode default 'C128A',
            barcdata(50) type c lower case default '1234567890',
            filename type string LOWER CASE default 'C:\usr\yourfile.bmp'.

DATA: errmsg(80)   TYPE c,
      bc_cmd       LIKE itcoo,
      bp_cmd       LIKE itcoo,
      bitmapsize   TYPE i,
      bitmap2_size TYPE i,
      w            TYPE i,
      h            TYPE i,
      bitmap       LIKE rspolpbi OCCURS 10 WITH HEADER LINE,
      bitmap2      LIKE rspolpbi OCCURS 10 WITH HEADER LINE,
      l_bitmap     TYPE xstring,
      otf          LIKE itcoo OCCURS 10 WITH HEADER LINE.

PERFORM get_otf_bc_cmd  IN PROGRAM sapmssco
                       USING barcode
                             barcdata
                             bc_cmd.
CHECK sy-subrc = 0.
bp_cmd-tdprintcom = 'BP'.
PERFORM get_otf_bp_cmd  IN PROGRAM sapmssco
                       USING barcode
                             bp_cmd-tdprintpar.

CHECK sy-subrc = 0.
PERFORM renderbarcode IN PROGRAM sapmssco
                     TABLES bitmap
                      USING bc_cmd
                            bp_cmd
                            barcdata
                            bitmapsize
                            w
                            h
                            errmsg.
CHECK sy-subrc = 0.
perform bitmap2otf IN PROGRAM sapmssco
                   tables bitmap
                          otf
                    using bitmapsize
                          w
                          h.
data length type i.
data hex type xstring.
data bitmap3 type xstring.
FIELD-SYMBOLS  type x.

clear: hex, bitmap3.
loop at otf.
  length = otf-tdprintpar+2(2).
  assign otf-tdprintpar+4(length) to  casting.
  hex = (length).
  concatenate bitmap3 hex into bitmap3 in BYTE MODE.
endloop.

* convert from old format to new format
hex = 'FFFFFFFF01010000'.
CONCATENATE bitmap3(8) hex bitmap3+8 into bitmap3 in BYTE MODE.
clear hex.
shift hex right by 90 places in BYTE MODE.
CONCATENATE bitmap3(42) hex bitmap3+42 into bitmap3 in BYTE MODE.

data bitmap4 type SBDST_CONTENT.
  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer                = bitmap3 " xstring
    TABLES
      binary_tab            = bitmap4.
data bitmap4_size type i.
bitmap4_size = xstrlen( bitmap3 ).

CALL FUNCTION 'SAPSCRIPT_CONVERT_BITMAP'
 EXPORTING
   OLD_FORMAT                     = 'BDS'
   NEW_FORMAT                     = 'BMP'
   BITMAP_FILE_BYTECOUNT_IN       = bitmap4_size
 IMPORTING
   BITMAP_FILE_BYTECOUNT          = bitmap2_size
  TABLES
    bitmap_file                    = bitmap2
   BDS_BITMAP_FILE                = BITMAP4
 EXCEPTIONS
   NO_BITMAP_FILE                 = 1
   FORMAT_NOT_SUPPORTED           = 2
   BITMAP_FILE_NOT_TYPE_X         = 3
   NO_BMP_FILE                    = 4
   BMPERR_INVALID_FORMAT          = 5
   BMPERR_NO_COLORTABLE           = 6
   BMPERR_UNSUP_COMPRESSION       = 7
   BMPERR_CORRUPT_RLE_DATA        = 8
   BMPERR_EOF                     = 9
   BDSERR_INVALID_FORMAT          = 10
   BDSERR_EOF                     = 11.

  CALL METHOD cl_gui_frontend_services=>gui_download
    EXPORTING
      bin_filesize = bitmap2_size
      filename     = filename
      filetype     = 'BIN'
    CHANGING
      data_tab     = bitmap2[]
    EXCEPTIONS
      OTHERS       = 3.
10 REPLIES 10

Sandra_Rossi
Active Contributor
0 Kudos

You are trying to do something not provided by SAP. I think the OTF only contains the general barcode parameters, not the graphics, which are in fact generated by the OTF driver (while sending to the printer, it converts the OTF to the Page Description Language of the printer). I don't even know what the OTF driver triggers, ABAP program or system program.

Juwin
Active Contributor
0 Kudos

If you just need barcode bitmap image, check how the barcode printing example program (RSPO0031) works. It generates the bitmap image to show that in the print preview.

Subroutine:  brltest_preview,  renderbarcode.

This is also called when you try to convert OTF to PDF. OTF data for barcode is converted to a bitmap image to be included in the PDF file.

Hence, I feel that, the conversion routines from barcode OTF to its bitmap, exists in ECC.... just need to be explored.

Thanks, Juwin

0 Kudos

Hi Juwin

Thanks for your reply. The program and code you mentioned are the same which i mentioned in my original post (sapmssco).

As i already told, bitmap data exist but if i download this bitmap data using GUI_DOWNLOAD, then upon opening file it gives error ""This is not a valid bitmap file, or its format is not currently supported"'.

It seems, need to add additional header details to download into proper bitmap which i am not able to get. If you have any other inputs, let me know.

Sandra_Rossi
Active Contributor
0 Kudos

I guess the returned format contains the bitmap, but is not exactly a BMP file. SAPMSSCO adds a header which is only for OTF ("OTFbitma..."). Instead, we should add a header part for BMP files -> https://en.wikipedia.org/wiki/BMP_file_format

I don't even know what exact BMP format is returned by RENDERBARCODE subroutine (monochrome probably...)

Juwin
Active Contributor
0 Kudos

Hi,

Have a look at subroutine FILL_BMFILE_FROM_BMP in program LSTXBITMAPSF03. It has decoding logic to read from BMP file. Probably you may be able to reverse engineer and encode the BMP header.

Thanks, Juwin

Sandra_Rossi
Active Contributor

Okay now I'm sure it's possible to do it! (owing to Juwin findings)

REPORT.
PARAMETERS: barcode like tfo05-tdbarcode default 'C128A',
            barcdata(50) type c lower case default '1234567890',
            filename type string LOWER CASE default 'C:\usr\yourfile.bmp'.

DATA: errmsg(80)   TYPE c,
      bc_cmd       LIKE itcoo,
      bp_cmd       LIKE itcoo,
      bitmapsize   TYPE i,
      bitmap2_size TYPE i,
      w            TYPE i,
      h            TYPE i,
      bitmap       LIKE rspolpbi OCCURS 10 WITH HEADER LINE,
      bitmap2      LIKE rspolpbi OCCURS 10 WITH HEADER LINE,
      l_bitmap     TYPE xstring,
      otf          LIKE itcoo OCCURS 10 WITH HEADER LINE.

PERFORM get_otf_bc_cmd  IN PROGRAM sapmssco
                       USING barcode
                             barcdata
                             bc_cmd.
CHECK sy-subrc = 0.
bp_cmd-tdprintcom = 'BP'.
PERFORM get_otf_bp_cmd  IN PROGRAM sapmssco
                       USING barcode
                             bp_cmd-tdprintpar.

CHECK sy-subrc = 0.
PERFORM renderbarcode IN PROGRAM sapmssco
                     TABLES bitmap
                      USING bc_cmd
                            bp_cmd
                            barcdata
                            bitmapsize
                            w
                            h
                            errmsg.
CHECK sy-subrc = 0.
perform bitmap2otf IN PROGRAM sapmssco
                   tables bitmap
                          otf
                    using bitmapsize
                          w
                          h.
data length type i.
data hex type xstring.
data bitmap3 type xstring.
FIELD-SYMBOLS  type x.

clear: hex, bitmap3.
loop at otf.
  length = otf-tdprintpar+2(2).
  assign otf-tdprintpar+4(length) to  casting.
  hex = (length).
  concatenate bitmap3 hex into bitmap3 in BYTE MODE.
endloop.

* convert from old format to new format
hex = 'FFFFFFFF01010000'.
CONCATENATE bitmap3(8) hex bitmap3+8 into bitmap3 in BYTE MODE.
clear hex.
shift hex right by 90 places in BYTE MODE.
CONCATENATE bitmap3(42) hex bitmap3+42 into bitmap3 in BYTE MODE.

data bitmap4 type SBDST_CONTENT.
  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer                = bitmap3 " xstring
    TABLES
      binary_tab            = bitmap4.
data bitmap4_size type i.
bitmap4_size = xstrlen( bitmap3 ).

CALL FUNCTION 'SAPSCRIPT_CONVERT_BITMAP'
 EXPORTING
   OLD_FORMAT                     = 'BDS'
   NEW_FORMAT                     = 'BMP'
   BITMAP_FILE_BYTECOUNT_IN       = bitmap4_size
 IMPORTING
   BITMAP_FILE_BYTECOUNT          = bitmap2_size
  TABLES
    bitmap_file                    = bitmap2
   BDS_BITMAP_FILE                = BITMAP4
 EXCEPTIONS
   NO_BITMAP_FILE                 = 1
   FORMAT_NOT_SUPPORTED           = 2
   BITMAP_FILE_NOT_TYPE_X         = 3
   NO_BMP_FILE                    = 4
   BMPERR_INVALID_FORMAT          = 5
   BMPERR_NO_COLORTABLE           = 6
   BMPERR_UNSUP_COMPRESSION       = 7
   BMPERR_CORRUPT_RLE_DATA        = 8
   BMPERR_EOF                     = 9
   BDSERR_INVALID_FORMAT          = 10
   BDSERR_EOF                     = 11.

  CALL METHOD cl_gui_frontend_services=>gui_download
    EXPORTING
      bin_filesize = bitmap2_size
      filename     = filename
      filetype     = 'BIN'
    CHANGING
      data_tab     = bitmap2[]
    EXCEPTIONS
      OTHERS       = 3.

Juwin
Active Contributor
0 Kudos

Beautiful.....!!!

In the code snippet above, the field symbol name is missing. Please correct it.

data length type i.

data hex type xstring.

data bitmap3 type xstring.

FIELD-SYMBOLS <fs> type x.

clear: hex, bitmap3.

loop at otf.

  length = otf-tdprintpar+2(2).

  assign otf-tdprintpar+4(length) to <fs> casting.

  hex = <fs>(length).

  concatenate bitmap3 hex into bitmap3 in BYTE MODE.

endloop.

Thanks.

matt
Active Contributor
0 Kudos

I really hope you're not suggesting that a field symbol should have the name <fs>. That would make me sad.

0 Kudos

@Juwin, sorry I don't have the edit button anymore to correct it

(that's because I need to workaround the SCN editor which doesn't work well with my IE 11)

@Matt, my code is often very ugly when I rush!

0 Kudos

Sandra, don't worry: Nobody loves the SCN editor as it just doesn'do what we can expect.

Time to dump it!

Just look at the downgoing usage of SCN after it tried to be facebook 🙂

Sorry, couldn't resist.

Clemens