public ByteMatrix encode(String contents,int width,int height,Map<EncodeHintType,Object> hints) throws WriterException {
  if (contents == null || contents.length() == 0) {
    throw new IllegalArgumentException("Found empty contents");
  }
  if (width < 0 || height < 0) {
    throw new IllegalArgumentException("Requested dimensions are too small: " + width + 'x'+ height);
  }
  ErrorCorrectionLevel errorCorrectionLevel=ErrorCorrectionLevel.L;
  if (hints != null) {
    ErrorCorrectionLevel requestedECLevel=(ErrorCorrectionLevel)hints.get(EncodeHintType.ERROR_CORRECTION);
    if (requestedECLevel != null) {
      errorCorrectionLevel=requestedECLevel;
    }
  }
  QRCode code=new QRCode();
  Encoder.encode(contents,errorCorrectionLevel,hints,code);
  return renderResult(code,width,height);
}

public ByteMatrix encode ( String contents , int width , int height , Map < EncodeHintType , Object > hints ) throws WriterException { if ( contents == null || contents . length ( ) == 0 ) { throw new IllegalArgumentException ( "Found empty contents" ) ; } if ( width < 0 || height < 0 ) { throw new IllegalArgumentException ( "Requested dimensions are too small: " + width + 'x' + height ) ; } ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel . L ; if ( hints != null ) { ErrorCorrectionLevel requestedECLevel = ( ErrorCorrectionLevel ) hints . get ( EncodeHintType . ERROR_CORRECTION ) ; if ( requestedECLevel != null ) { errorCorrectionLevel = requestedECLevel ; } } QRCode code = new QRCode ( ) ; Encoder . encode ( contents , errorCorrectionLevel , hints , code ) ; return renderResult ( code , width , height ) ; }
encode a string into a qr code with dimensions width x height . hints contains suggestions for error - correction level and version . the default error - correction level is l , the default version is the smallest version for which the contents will fit into the qr - code .
