Skip to content
Marco Antonio edited this page Dec 4, 2021 · 5 revisions

Requirements

  • one image.
  • one Bitonal implementation algorithm to define the dithering.
  • one ImageWrapperInterface implementation to determine the command set to be used.

The image

One regular image (png, jpg...)

The Bitonal implementation algorithm

We have two buitin implementation for this:

BitonalThreshold:

output

// using bitonal threshold for dithering
Bitonal algorithm = new BitonalThreshold(); 

BitonalOrderedDither:

output

Bitonal algorithm = new BitonalOrderedDither();

Dithering sample

The ImageWrapperInterface implementation

RasterBitImageWrapper

This implementation of ImageWrapperInterface uses esc/pos sequence: "GS 'v' '0'"

RasterBitImageWrapper imageWrapper = new RasterBitImageWrapper();

sample RasterBitImageWrapper

GraphicsImageWrapper

This implementation of ImageWrapperInterface uses esc/pos sequence: "GS(L"

GraphicsImageWrapper imageWrapper = new GraphicsImageWrapper();

sample GraphicsImageWrapper

BitImageWrapper

This implementation of ImageWrapperInterface uses esc/pos sequence: "ESC '*'"

BitImageWrapper imageWrapper = new BitImageWrapper();

sample BitImageWrapper

As you can see, we have three implementation, but wich one is the best choice? To answer this you need to know about your printer cababilities and what of this works better for you, you can test printer speed and quality of the printed image. Personally, my preference of use is RasterBitImageWrapper, then GraphicsImageWrapper and than BitImageWrapper. Besides this, not every printer recognizes all three standards and can print unexpected characters.

extensive images

if you want to print ample(big) images like longs jpg/pdf receipts, then take a look at Slice image sample to see how to use the ImageHelper class

        ImageHelper helper = new ImageHelper();
        Bitonal algorithm = new BitonalThreshold();
        GraphicsImageWrapper imageWrapper = new GraphicsImageWrapper();
        helper.write(escPos, new CoffeeImageImpl(image),imageWrapper,algorithm);

        escPos.feed(5).cut(EscPos.CutMode.FULL);
        escPos.close();