本文整理汇总了C#中ZXing.Common.BitMatrix类的典型用法代码示例。如果您正苦于以下问题:C# BitMatrix类的具体用法?C# BitMatrix怎么用?C# BitMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BitMatrix类属于ZXing.Common命名空间,在下文中一共展示了BitMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: sampleGrid
public override BitMatrix sampleGrid(BitMatrix image, int dimensionX, int dimensionY, float p1ToX, float p1ToY, float p2ToX, float p2ToY, float p3ToX, float p3ToY, float p4ToX, float p4ToY, float p1FromX, float p1FromY, float p2FromX, float p2FromY, float p3FromX, float p3FromY, float p4FromX, float p4FromY)
{
PerspectiveTransform transform = PerspectiveTransform.quadrilateralToQuadrilateral(
p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY,
p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY);
return sampleGrid(image, dimensionX, dimensionY, transform);
}
示例3: BinaryBitmap
internal BinaryBitmap(BitMatrix matrix)
{
if (matrix == null)
{
throw new ArgumentException("matrix must be non-null.");
}
this.matrix = matrix;
}
示例4: sampleGrid
public override BitMatrix sampleGrid(BitMatrix image, int dimensionX, int dimensionY, PerspectiveTransform transform)
{
if (dimensionX <= 0 || dimensionY <= 0)
{
return null;
}
BitMatrix bits = new BitMatrix(dimensionX, dimensionY);
float[] points = new float[dimensionX << 1];
for (int y = 0; y < dimensionY; y++)
{
int max = points.Length;
//UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
float iValue = (float)y + 0.5f;
for (int x = 0; x < max; x += 2)
{
//UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
points[x] = (float)(x >> 1) + 0.5f;
points[x + 1] = iValue;
}
transform.transformPoints(points);
// Quick check to see if points transformed to something inside the image;
// sufficient to check the endpoints
if (!checkAndNudgePoints(image, points))
return null;
try
{
var imageWidth = image.Width;
var imageHeight = image.Height;
for (int x = 0; x < max; x += 2)
{
var imagex = (int)points[x];
var imagey = (int)points[x + 1];
if (imagex < 0 || imagex >= imageWidth || imagey < 0 || imagey >= imageHeight)
{
return null;
}
bits[x >> 1, y] = image[imagex, imagey];
}
}
catch (System.IndexOutOfRangeException)
{
// java version:
//
// This feels wrong, but, sometimes if the finder patterns are misidentified, the resulting
// transform gets "twisted" such that it maps a straight line of points to a set of points
// whose endpoints are in bounds, but others are not. There is probably some mathematical
// way to detect this about the transformation that I don't know yet.
// This results in an ugly runtime exception despite our clever checks above -- can't have
// that. We could check each point's coordinates but that feels duplicative. We settle for
// catching and wrapping ArrayIndexOutOfBoundsException.
return null;
}
}
return bits;
}
示例5: createBitMatrixParser
/// <param name="bitMatrix">{@link BitMatrix} to parse</param>
/// <throws>ReaderException if dimension is not >= 21 and 1 mod 4</throws>
internal static BitMatrixParser createBitMatrixParser(BitMatrix bitMatrix)
{
int dimension = bitMatrix.Height;
if (dimension < 21 || (dimension & 0x03) != 1)
{
return null;
}
return new BitMatrixParser(bitMatrix);
}
示例6: AztecDetectorResult
/// <summary>
/// Initializes a new instance of the <see cref="AztecDetectorResult"/> class.
/// </summary>
/// <param name="bits">The bits.</param>
/// <param name="points">The points.</param>
/// <param name="compact">if set to <c>true</c> [compact].</param>
/// <param name="nbDatablocks">The nb datablocks.</param>
/// <param name="nbLayers">The nb layers.</param>
public AztecDetectorResult(BitMatrix bits,
ResultPoint[] points,
bool compact,
int nbDatablocks,
int nbLayers)
: base(bits, points)
{
Compact = compact;
NbDatablocks = nbDatablocks;
NbLayers = nbLayers;
}
示例7: unmaskBitMatrix
/// <summary> <p>Implementations of this method reverse the data masking process applied to a QR Code and
/// make its bits ready to read.</p>
/// </summary>
/// <param name="reference"></param>
/// <param name="bits">representation of QR Code bits</param>
/// <param name="dimension">dimension of QR Code, represented by bits, being unmasked</param>
internal static void unmaskBitMatrix(int reference, BitMatrix bits, int dimension)
{
if (reference < 0 || reference > 7)
{
throw new System.ArgumentException();
}
var isMasked = DATA_MASKS[reference];
bits.flipWhen(isMasked);
}
示例8: AlignmentPatternFinder
/// <summary> <p>Creates a finder that will look in a portion of the whole image.</p>
///
/// </summary>
/// <param name="image">image to search
/// </param>
/// <param name="startX">left column from which to start searching
/// </param>
/// <param name="startY">top row from which to start searching
/// </param>
/// <param name="width">width of region to search
/// </param>
/// <param name="height">height of region to search
/// </param>
/// <param name="moduleSize">estimated module size so far
/// </param>
internal AlignmentPatternFinder(BitMatrix image, int startX, int startY, int width, int height, float moduleSize, ResultPointCallback resultPointCallback)
{
this.image = image;
this.possibleCenters = new List<AlignmentPattern>(5);
this.startX = startX;
this.startY = startY;
this.width = width;
this.height = height;
this.moduleSize = moduleSize;
this.crossCheckStateCount = new int[3];
this.resultPointCallback = resultPointCallback;
}
示例9: decode
/// <summary>
/// <p>Convenience method that can decode a QR Code represented as a 2D array of booleans.
/// "true" is taken to mean a black module.</p>
/// </summary>
/// <param name="image">booleans representing white/black QR Code modules</param>
/// <param name="hints">The hints.</param>
/// <returns>
/// text and bytes encoded within the QR Code
/// </returns>
public DecoderResult decode(bool[][] image, IDictionary<DecodeHintType, object> hints)
{
int dimension = image.Length;
BitMatrix bits = new BitMatrix(dimension);
for (int i = 0; i < dimension; i++)
{
for (int j = 0; j < dimension; j++)
{
bits[j, i] = image[i][j];
}
}
return decode(bits, hints);
}
示例10: BoundingBox
/// <summary>
/// Initializes a new instance of the <see cref="ZXing.PDF417.Internal.BoundingBox"/> class.
/// Will throw an exception if the corner points don't match up correctly
/// </summary>
/// <param name="image">Image.</param>
/// <param name="topLeft">Top left.</param>
/// <param name="topRight">Top right.</param>
/// <param name="bottomLeft">Bottom left.</param>
/// <param name="bottomRight">Bottom right.</param>
private BoundingBox(BitMatrix image,
ResultPoint topLeft,
ResultPoint bottomLeft,
ResultPoint topRight,
ResultPoint bottomRight)
{
this.image = image;
this.TopLeft = topLeft;
this.TopRight = topRight;
this.BottomLeft = bottomLeft;
this.BottomRight = bottomRight;
calculateMinMaxValues();
}
示例11: unmaskBitMatrix
/// <summary> <p>Implementations of this method reverse the data masking process applied to a QR Code and
/// make its bits ready to read.</p>
///
/// </summary>
/// <param name="bits">representation of QR Code bits
/// </param>
/// <param name="dimension">dimension of QR Code, represented by bits, being unmasked
/// </param>
internal void unmaskBitMatrix(BitMatrix bits, int dimension)
{
for (int i = 0; i < dimension; i++)
{
for (int j = 0; j < dimension; j++)
{
if (isMasked(i, j))
{
bits.flip(j, i);
}
}
}
}
示例12: BitMatrixParser
/// <summary>
/// <param name="bitMatrix"><see cref="BitMatrix" />to parse</param>
/// <exception cref="FormatException">if dimension is < 8 or >144 or not 0 mod 2</exception>
/// </summary>
internal BitMatrixParser(BitMatrix bitMatrix)
{
int dimension = bitMatrix.Height;
if (dimension < 8 || dimension > 144 || (dimension & 0x01) != 0)
{
return;
}
version = readVersion(bitMatrix);
if (version != null)
{
mappingBitMatrix = extractDataRegion(bitMatrix);
readMappingMatrix = new BitMatrix(mappingBitMatrix.Width, mappingBitMatrix.Height);
}
}
示例13: decode
/// <summary>
/// <p>Convenience method that can decode a Data Matrix Code represented as a 2D array of booleans.
/// "true" is taken to mean a black module.</p>
///
/// <param name="image">booleans representing white/black Data Matrix Code modules</param>
/// <returns>text and bytes encoded within the Data Matrix Code</returns>
/// <exception cref="FormatException">if the Data Matrix Code cannot be decoded</exception>
/// <exception cref="ChecksumException">if error correction fails</exception>
/// </summary>
public DecoderResult decode(bool[][] image)
{
int dimension = image.Length;
BitMatrix bits = new BitMatrix(dimension);
for (int i = 0; i < dimension; i++)
{
for (int j = 0; j < dimension; j++)
{
if (image[i][j])
{
bits[j, i] = true;
}
}
}
return decode(bits);
}
示例14: Create
/// <summary>
/// Initializes a new instance of the <see cref="ZXing.PDF417.Internal.BoundingBox"/> class.
/// returns null if the corner points don't match up correctly
/// </summary>
/// <param name="image">The image.</param>
/// <param name="topLeft">The top left.</param>
/// <param name="bottomLeft">The bottom left.</param>
/// <param name="topRight">The top right.</param>
/// <param name="bottomRight">The bottom right.</param>
/// <returns></returns>
public static BoundingBox Create(BitMatrix image,
ResultPoint topLeft,
ResultPoint bottomLeft,
ResultPoint topRight,
ResultPoint bottomRight)
{
if ((topLeft == null && topRight == null) ||
(bottomLeft == null && bottomRight == null) ||
(topLeft != null && bottomLeft == null) ||
(topRight != null && bottomRight == null))
{
return null;
}
return new BoundingBox(image, topLeft, bottomLeft, topRight, bottomRight);
}
示例15: decode
/// <summary>
/// <p>Decodes a QR Code represented as a {@link BitMatrix}. A 1 or "true" is taken to mean a black module.</p>
/// </summary>
/// <param name="bits">booleans representing white/black QR Code modules</param>
/// <param name="hints">The hints.</param>
/// <returns>
/// text and bytes encoded within the QR Code
/// </returns>
public DecoderResult decode(BitMatrix bits, IDictionary<DecodeHintType, object> hints)
{
// Construct a parser and read version, error-correction level
var parser = BitMatrixParser.createBitMatrixParser(bits);
if (parser == null)
return null;
var result = decode(parser, hints);
if (result == null)
{
// Revert the bit matrix
parser.remask();
// Will be attempting a mirrored reading of the version and format info.
parser.setMirror(true);
// Preemptively read the version.
var version = parser.readVersion();
if (version == null)
return null;
// Preemptively read the format information.
var formatinfo = parser.readFormatInformation();
if (formatinfo == null)
return null;
/*
* Since we're here, this means we have successfully detected some kind
* of version and format information when mirrored. This is a good sign,
* that the QR code may be mirrored, and we should try once more with a
* mirrored content.
*/
// Prepare for a mirrored reading.
parser.mirror();
result = decode(parser, hints);
if (result != null)
{
// Success! Notify the caller that the code was mirrored.
result.Other = new QRCodeDecoderMetaData(true);
}
}
return result;
}