本文整理汇总了C#中BarcodeFormat类的典型用法代码示例。如果您正苦于以下问题:C# BarcodeFormat类的具体用法?C# BarcodeFormat怎么用?C# BarcodeFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BarcodeFormat类属于命名空间,在下文中一共展示了BarcodeFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: encode
/// <summary>
/// </summary>
/// <param name="contents">The contents to encode in the barcode</param>
/// <param name="format">The barcode format to generate</param>
/// <param name="width">The preferred width in pixels</param>
/// <param name="height">The preferred height in pixels</param>
/// <param name="hints">Additional parameters to supply to the encoder</param>
/// <returns>
/// The generated barcode as a Matrix of unsigned bytes (0 == black, 255 == white)
/// </returns>
public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, IDictionary<EncodeHintType, object> hints)
{
Encoding charset = DEFAULT_CHARSET;
int? eccPercent = null;
if (hints != null)
{
if (hints.ContainsKey(EncodeHintType.CHARACTER_SET))
{
object charsetname = hints[EncodeHintType.CHARACTER_SET];
if (charsetname != null)
{
charset = Encoding.GetEncoding(charsetname.ToString());
}
}
if (hints.ContainsKey(EncodeHintType.ERROR_CORRECTION))
{
object eccPercentObject = hints[EncodeHintType.ERROR_CORRECTION];
if (eccPercentObject != null)
{
eccPercent = Convert.ToInt32(eccPercentObject);
}
}
}
return encode(contents,
format,
charset,
eccPercent == null ? Internal.Encoder.DEFAULT_EC_PERCENT : eccPercent.Value);
}
示例2: encode
public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, IDictionary<EncodeHintType, object> hints)
{
if (!formatMap.ContainsKey(format))
throw new ArgumentException("No encoder available for format " + format);
return formatMap[format]().encode(contents, format, width, height, hints);
}
示例3: encode
/// <summary>
/// Encode the contents following specified format.
/// {@code width} and {@code height} are required size. This method may return bigger size
/// {@code BitMatrix} when specified size is too small. The user can set both {@code width} and
/// {@code height} to zero to get minimum size barcode. If negative value is set to {@code width}
/// or {@code height}, {@code IllegalArgumentException} is thrown.
/// </summary>
public virtual BitMatrix encode(String contents,
BarcodeFormat format,
int width,
int height,
IDictionary<EncodeHintType, object> hints)
{
if (contents.Length == 0)
{
throw new ArgumentException("Found empty contents");
}
if (width < 0 || height < 0)
{
throw new ArgumentException("Negative size is not allowed. Input: "
+ width + 'x' + height);
}
int sidesMargin = DefaultMargin;
if (hints != null)
{
var sidesMarginInt = hints.ContainsKey(EncodeHintType.MARGIN) ? (int)hints[EncodeHintType.MARGIN] : (int?)null;
if (sidesMarginInt != null)
{
sidesMargin = sidesMarginInt.Value;
}
}
var code = encode(contents);
return renderResult(code, width, height, sidesMargin);
}
示例4: encode
public ByteMatrix encode(String contents, BarcodeFormat format, int width, int height,Hashtable hints)
{
if (contents == null || contents.Length == 0) {
throw new ArgumentException("Found empty contents");
}
if (format != BarcodeFormat.QR_CODE) {
throw new ArgumentException("Can only encode QR_CODE, but got " + format);
}
if (width < 0 || height < 0) {
throw new ArgumentException("Requested dimensions are too small: " + width + 'x' +
height);
}
ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
if (hints != null) {
ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel) hints[EncodeHintType.ERROR_CORRECTION];
if (requestedECLevel != null) {
errorCorrectionLevel = requestedECLevel;
}
}
QRCode code = new QRCode();
Encoder.encode(contents, errorCorrectionLevel, code);
return renderResult(code, width, height);
}
示例5: encode
public ByteMatrix encode(System.String contents, BarcodeFormat format, int width, int height, System.Collections.Generic.Dictionary<Object,Object> hints)
{
if (contents == null || contents.Length == 0)
{
throw new System.ArgumentException("Found empty contents");
}
if (format != BarcodeFormat.QR_CODE)
{
throw new System.ArgumentException("Can only encode QR_CODE, but got " + format);
}
if (width < 0 || height < 0)
{
throw new System.ArgumentException("Requested dimensions are too small: " + width + 'x' + height);
}
ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
if (hints != null && hints.ContainsKey(EncodeHintType.ERROR_CORRECTION))
{
errorCorrectionLevel = (ErrorCorrectionLevel)hints[EncodeHintType.ERROR_CORRECTION]; //UPGRADE: Fixed dictionary key grab issue
}
QRCode code = new QRCode();
Encoder.encode(contents, errorCorrectionLevel, hints, code);
return renderResult(code, width, height);
}
示例6: Result
/// <summary>
/// Initializes a new instance of the <see cref="Result"/> class.
/// </summary>
/// <param name="text">The text.</param>
/// <param name="rawBytes">The raw bytes.</param>
/// <param name="resultPoints">The result points.</param>
/// <param name="format">The format.</param>
public Result(String text,
byte[] rawBytes,
ResultPoint[] resultPoints,
BarcodeFormat format)
: this(text, rawBytes, resultPoints, format, DateTime.Now.Ticks)
{
}
示例7: Render
public override Bitmap Render(BitMatrix matrix, BarcodeFormat format, string content, EncodingOptions options)
{
int width = matrix.Width;
int height = matrix.Height;
var backgroundBrush = new LinearGradientBrush(
new Rectangle(0, 0, width, height), BackgroundGradientColor, Background, LinearGradientMode.Vertical);
var foregroundBrush = new LinearGradientBrush(
new Rectangle(0, 0, width, height), ForegroundGradientColor, Foreground, LinearGradientMode.ForwardDiagonal);
var bmp = new Bitmap(width, height);
var gg = Graphics.FromImage(bmp);
gg.Clear(Background);
for (int x = 0; x < width - 1; x++)
{
for (int y = 0; y < height - 1; y++)
{
if (matrix[x, y])
{
gg.FillRectangle(foregroundBrush, x, y, 1, 1);
}
else
{
gg.FillRectangle(backgroundBrush, x, y, 1, 1);
}
}
}
return bmp;
}
示例8: encode
/// <summary>
///
/// </summary>
/// <param name="contents"></param>
/// <param name="format"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="hints"></param>
/// <returns></returns>
public ByteMatrix encode(System.String contents, BarcodeFormat format, int width, int height, System.Collections.Hashtable hints)
{
if (contents == null || contents.Length == 0)
{
throw new System.ArgumentException("Found empty contents");
}
if (format != BarcodeFormat.MICRO_QR_CODE)
{
throw new System.ArgumentException("Can only encode QR_CODE, but got " + format);
}
if (width < 0 || height < 0)
{
throw new System.ArgumentException("Requested dimensions are too small: " + width + 'x' + height);
}
ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
int cVersionNum = -1;
if (hints != null)
{
ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel)hints[EncodeHintType.ERROR_CORRECTION];
if (requestedECLevel != null)
{
errorCorrectionLevel = requestedECLevel;
}
int versionNum = (int)hints[EncodeHintType.MICROQRCODE_VERSION];
if (versionNum >= 1 && versionNum <= 4)
cVersionNum = versionNum;
}
MicroQRCode code = new MicroQRCode();
Encoder.encode(contents, errorCorrectionLevel, hints, code, cVersionNum);
return renderResult(code, width, height);
}
示例9: encode
/// <summary>
/// </summary>
/// <param name="contents">The contents to encode in the barcode</param>
/// <param name="format">The barcode format to generate</param>
/// <param name="width">The preferred width in pixels</param>
/// <param name="height">The preferred height in pixels</param>
/// <param name="hints">Additional parameters to supply to the encoder</param>
/// <returns>
/// The generated barcode as a Matrix of unsigned bytes (0 == black, 255 == white)
/// </returns>
public BitMatrix encode(String contents,
BarcodeFormat format,
int width,
int height,
IDictionary<EncodeHintType, object> hints)
{
if (format != BarcodeFormat.PDF_417)
{
throw new ArgumentException("Can only encode PDF_417, but got " + format);
}
var encoder = new Internal.PDF417();
if (hints != null)
{
if (hints.ContainsKey(EncodeHintType.PDF417_COMPACT))
{
encoder.setCompact((Boolean) hints[EncodeHintType.PDF417_COMPACT]);
}
if (hints.ContainsKey(EncodeHintType.PDF417_COMPACTION))
{
encoder.setCompaction((Compaction) hints[EncodeHintType.PDF417_COMPACTION]);
}
if (hints.ContainsKey(EncodeHintType.PDF417_DIMENSIONS))
{
Dimensions dimensions = (Dimensions) hints[EncodeHintType.PDF417_DIMENSIONS];
encoder.setDimensions(dimensions.MaxCols,
dimensions.MinCols,
dimensions.MaxRows,
dimensions.MinRows);
}
}
return bitMatrixFromEncoder(encoder, contents, width, height);
}
示例10: Result
/// <summary>
/// Initializes a new instance of the <see cref="Result"/> class.
/// </summary>
/// <param name="text">The text.</param>
/// <param name="rawBytes">The raw bytes.</param>
/// <param name="resultPoints">The result points.</param>
/// <param name="format">The format.</param>
public Result(String text,
[System.Runtime.InteropServices.WindowsRuntime.ReadOnlyArray] byte[] rawBytes,
[System.Runtime.InteropServices.WindowsRuntime.ReadOnlyArray] ResultPoint[] resultPoints,
BarcodeFormat format)
: this(text, rawBytes, resultPoints, format, DateTime.Now.Ticks)
{
}
示例11: GetReader
/// <summary>
/// Returns the zxing reader class for the current specified ScanMode.
/// </summary>
/// <returns></returns>
internal static BarcodeReader GetReader(BarcodeFormat format = BarcodeFormat.All_1D)
{
return new BarcodeReader()
{
AutoRotate = true,
Options = new ZXing.Common.DecodingOptions() { TryHarder = false, PossibleFormats = new BarcodeFormat[] { format } }
};
}
示例12: encode
private const int codeWidth = 3 + (7 * 4) + 5 + (7 * 4) + 3; // end guard
#endregion Fields
#region Methods
public override ByteMatrix encode(System.String contents, BarcodeFormat format, int width, int height, System.Collections.Generic.Dictionary <Object,Object> hints)
{
if (format != BarcodeFormat.EAN_8)
{
throw new System.ArgumentException("Can only encode EAN_8, but got " + format);
}
return base.encode(contents, format, width, height, hints);
}
示例13: encode
public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, IDictionary<EncodeHintType, object> hints)
{
if (String.IsNullOrEmpty(contents))
{
throw new ArgumentException("Found empty contents", contents);
}
if (format != BarcodeFormat.DATA_MATRIX)
{
throw new ArgumentException("Can only encode DATA_MATRIX, but got " + format);
}
if (width < 0 || height < 0)
{
throw new ArgumentException("Requested dimensions are too small: " + width + 'x' + height);
}
// Try to get force shape & min / max size
SymbolShapeHint shape = SymbolShapeHint.FORCE_NONE;
Dimension minSize = null;
Dimension maxSize = null;
if (hints != null)
{
var requestedShape = hints.ContainsKey(EncodeHintType.DATA_MATRIX_SHAPE) ? (SymbolShapeHint?)hints[EncodeHintType.DATA_MATRIX_SHAPE] : null;
if (requestedShape != null)
{
shape = requestedShape.Value;
}
var requestedMinSize = hints.ContainsKey(EncodeHintType.MIN_SIZE) ? (Dimension)hints[EncodeHintType.MIN_SIZE] : null;
if (requestedMinSize != null)
{
minSize = requestedMinSize;
}
var requestedMaxSize = hints.ContainsKey(EncodeHintType.MAX_SIZE) ? (Dimension)hints[EncodeHintType.MAX_SIZE] : null;
if (requestedMaxSize != null)
{
maxSize = requestedMaxSize;
}
}
//1. step: Data encodation
String encoded = HighLevelEncoder.encodeHighLevel(contents, shape, minSize, maxSize);
SymbolInfo symbolInfo = SymbolInfo.lookup(encoded.Length, shape, minSize, maxSize, true);
//2. step: ECC generation
String codewords = ErrorCorrection.encodeECC200(encoded, symbolInfo);
//3. step: Module placement in Matrix
var placement =
new DefaultPlacement(codewords, symbolInfo.getSymbolDataWidth(), symbolInfo.getSymbolDataHeight());
placement.place();
//4. step: low-level encoding
return encodeLowLevel(placement, symbolInfo);
}
示例14: doTest
private static void doTest(String contents, String normalized, BarcodeFormat format)
{
ZXing.Result fakeResult = new ZXing.Result(contents, null, null, format);
ParsedResult result = ResultParser.parseResult(fakeResult);
Assert.AreEqual(ParsedResultType.PRODUCT, result.Type);
ProductParsedResult productResult = (ProductParsedResult)result;
Assert.AreEqual(contents, productResult.ProductID);
Assert.AreEqual(normalized, productResult.NormalizedProductID);
}
示例15: Encode
private const int codeWidth = 3 + (7 * 6) + 5 + (7 * 6) + 3; // end guard
public override ByteMatrix Encode(System.String contents, BarcodeFormat format, int width, int height, System.Collections.Hashtable hints)
{
if (format != BarcodeFormat.EAN_13)
{
throw new System.ArgumentException("Can only encode EAN_13, but got " + format);
}
return base.Encode(contents, format, width, height, hints);
}