use of com.google.zxing.ResultPoint in project smartmodule by carozhu.
the class ViewfinderView method onDraw.
public void onDraw(Canvas canvas) {
if (cameraManager == null) {
// not ready yet, early draw before done configuring
return;
}
Rect frame = cameraManager.getFramingRect();
Rect previewFrame = cameraManager.getFramingRectInPreview();
if (frame == null || previewFrame == null) {
return;
}
// 初始化中间线滑动的最上边和最下边
if (!isFirst) {
isFirst = true;
slideTop = frame.top - 5;
}
int width = canvas.getWidth();
int height = canvas.getHeight();
// Draw the exterior (i.e. outside the framing rect) darkened
/*
* 预览界面的绘制
*/
paint.setColor(resultBitmap != null ? resultColor : maskColor);
canvas.drawRect(0, 0, width, frame.top - 1, paint);
canvas.drawRect(0, frame.top - 1, frame.left - 1, frame.bottom + 1, paint);
canvas.drawRect(frame.right + 1, frame.top - 1, width, frame.bottom + 1, paint);
canvas.drawRect(0, frame.bottom + 1, width, height, paint);
if (resultBitmap != null) {
// Draw the opaque result bitmap over the scanning rectangle
paint.setAlpha(OPAQUE);
// canvas.drawBitmap(resultBitmap, null, frame, paint);
canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint);
} else {
// 画扫预览灰线框,共4个部分
paint.setColor(Color.GRAY);
canvas.drawRect(frame.left, frame.top, frame.right, frame.top + L_WIDTH, paint);
canvas.drawRect(frame.left, frame.top, frame.left + L_WIDTH, frame.bottom, paint);
canvas.drawRect(frame.left, frame.bottom - L_WIDTH, frame.right, frame.bottom, paint);
canvas.drawRect(frame.right - L_WIDTH, frame.top, frame.right, frame.bottom, paint);
// 画扫描框边上的角,总共8个部分
paint.setColor(ConfigureManager.getConfigureManager().getAppThemeColor());
canvas.drawRect(frame.left, frame.top, frame.left + ScreenRate, frame.top + CORNER_WIDTH, paint);
canvas.drawRect(frame.left, frame.top, frame.left + CORNER_WIDTH, frame.top + ScreenRate, paint);
canvas.drawRect(frame.right - ScreenRate, frame.top, frame.right, frame.top + CORNER_WIDTH, paint);
canvas.drawRect(frame.right - CORNER_WIDTH, frame.top, frame.right, frame.top + ScreenRate, paint);
canvas.drawRect(frame.left, frame.bottom - CORNER_WIDTH, frame.left + ScreenRate, frame.bottom, paint);
canvas.drawRect(frame.left, frame.bottom - ScreenRate, frame.left + CORNER_WIDTH, frame.bottom, paint);
canvas.drawRect(frame.right - ScreenRate, frame.bottom - CORNER_WIDTH, frame.right, frame.bottom, paint);
canvas.drawRect(frame.right - CORNER_WIDTH, frame.bottom - ScreenRate, frame.right, frame.bottom, paint);
// 绘制中间的线,每次刷新界面,中间的线往下移动SPEEN_DISTANCE
slideTop += SPEEN_DISTANCE;
if (slideTop >= frame.bottom - 10) {
slideTop = frame.top - 5;
}
Rect lineRect = new Rect();
lineRect.left = frame.left;
lineRect.right = frame.right;
lineRect.top = slideTop;
// 扫描线的宽度15
lineRect.bottom = slideTop + MIDDLE_LINE_WIDTH;
// canvas.drawBitmap(((BitmapDrawable) (getResources()
// .getDrawable(R.drawable.qrcode_scan_line))).getBitmap(),
// null, lineRect, paint);
canvas.drawRect(lineRect, paint);
paint.setColor(Color.WHITE);
paint.setTextSize(15 * density);
paint.setAlpha(0xee);
paint.setTypeface(Typeface.create("System", Typeface.BOLD));
if ((CaptureActivity.currentState != null) && (CaptureActivity.currentState.equals("onecode"))) {
canvas.drawText(getResources().getString(R.string.scan_qrcode), frame.left + 8, (float) (frame.bottom + (float) 40 * density), paint);
}
if ((CaptureActivity.currentState != null) && (CaptureActivity.currentState.equals("qrcode"))) {
// canvas.drawText(getResources().getString(R.string.scan_qrcode), frame.left - 20, (float) (frame.bottom + (float) 40 * density), paint);
// canvas.drawText(getResources().getString(R.string.scan_qrcode), frame.centerX(), (float) (frame.bottom + (float) 40 * density), paint);
// Paint mPaint = new Paint();
// mPaint.setStrokeWidth(3);
// mPaint.setTextSize(15 * density);
// mPaint.setColor(Color.WHITE);
// mPaint.setTextAlign(Paint.Align.LEFT);
// mPaint.setAlpha(0xee);
// mPaint.setTypeface(Typeface.create("System", Typeface.BOLD));
// Rect bounds = new Rect();
// mPaint.getTextBounds(getResources().getString(R.string.scan_qrcode), 0, getResources().getString(R.string.scan_qrcode).length(), bounds);
// Paint.FontMetricsInt fontMetrics = mPaint.getFontMetricsInt();
// int baseline = (getMeasuredHeight() - fontMetrics.bottom + fontMetrics.top) / 2 - fontMetrics.top;
// canvas.drawText(getResources().getString(R.string.scan_qrcode),getMeasuredWidth() / 2 - bounds.width() / 2, (float) (frame.bottom + (float) 40 * density), mPaint);
}
List<ResultPoint> currentPossible = possibleResultPoints;
Collection<ResultPoint> currentLast = lastPossibleResultPoints;
if (currentPossible.isEmpty()) {
lastPossibleResultPoints = null;
} else {
possibleResultPoints = new ArrayList<ResultPoint>(5);
lastPossibleResultPoints = currentPossible;
paint.setAlpha(OPAQUE);
paint.setColor(resultPointColor);
for (ResultPoint point : currentPossible) {
canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 6.0f, paint);
}
}
if (currentLast != null) {
paint.setAlpha(OPAQUE / 2);
paint.setColor(resultPointColor);
for (ResultPoint point : currentLast) {
canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 3.0f, paint);
}
}
// 刷新界面区域
postInvalidateDelayed(ANIMATION_DELAY, 0, 0, width, height);
}
}
use of com.google.zxing.ResultPoint in project BarcodeEye by BarcodeEye.
the class CaptureActivity method drawResultPoints.
/**
* Superimpose a line for 1D or dots for 2D to highlight the key features of
* the barcode.
*
* @param barcode
* A bitmap of the captured image.
* @param scaleFactor
* amount by which thumbnail was scaled
* @param rawResult
* The decoded results which contains the points to draw.
*/
private static void drawResultPoints(Bitmap barcode, float scaleFactor, Result rawResult, int color) {
ResultPoint[] points = rawResult.getResultPoints();
if (points != null && points.length > 0) {
Canvas canvas = new Canvas(barcode);
Paint paint = new Paint();
paint.setColor(color);
if (points.length == 2) {
paint.setStrokeWidth(4.0f);
drawLine(canvas, paint, points[0], points[1], scaleFactor);
} else if (points.length == 4 && (rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A || rawResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) {
// Hacky special case -- draw two lines, for the barcode and metadata
drawLine(canvas, paint, points[0], points[1], scaleFactor);
drawLine(canvas, paint, points[2], points[3], scaleFactor);
} else {
paint.setStrokeWidth(10.0f);
for (ResultPoint point : points) {
if (point != null) {
canvas.drawPoint(scaleFactor * point.getX(), scaleFactor * point.getY(), paint);
}
}
}
}
}
use of com.google.zxing.ResultPoint in project BarcodeEye by BarcodeEye.
the class ViewfinderView method onDraw.
@Override
public void onDraw(Canvas canvas) {
if (cameraManager == null) {
// not ready yet, early draw before done configuring
return;
}
Rect frame = cameraManager.getFramingRect();
Rect previewFrame = cameraManager.getFramingRectInPreview();
if (frame == null || previewFrame == null) {
return;
}
int width = canvas.getWidth();
int height = canvas.getHeight();
// Draw the exterior (i.e. outside the framing rect) darkened
paint.setColor(resultBitmap != null ? resultColor : maskColor);
canvas.drawRect(0, 0, width, frame.top, paint);
canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);
canvas.drawRect(0, frame.bottom + 1, width, height, paint);
if (resultBitmap != null) {
// Draw the opaque result bitmap over the scanning rectangle
paint.setAlpha(CURRENT_POINT_OPACITY);
canvas.drawBitmap(resultBitmap, null, frame, paint);
} else {
// Draw a red "laser scanner" line through the middle to show decoding is active
paint.setColor(laserColor);
paint.setAlpha(SCANNER_ALPHA[scannerAlpha]);
scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length;
int middle = frame.height() / 2 + frame.top;
canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint);
float scaleX = frame.width() / (float) previewFrame.width();
float scaleY = frame.height() / (float) previewFrame.height();
List<ResultPoint> currentPossible = possibleResultPoints;
List<ResultPoint> currentLast = lastPossibleResultPoints;
int frameLeft = frame.left;
int frameTop = frame.top;
if (currentPossible.isEmpty()) {
lastPossibleResultPoints = null;
} else {
possibleResultPoints = new ArrayList<ResultPoint>(5);
lastPossibleResultPoints = currentPossible;
paint.setAlpha(CURRENT_POINT_OPACITY);
paint.setColor(resultPointColor);
synchronized (currentPossible) {
for (ResultPoint point : currentPossible) {
canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), POINT_SIZE, paint);
}
}
}
if (currentLast != null) {
paint.setAlpha(CURRENT_POINT_OPACITY / 2);
paint.setColor(resultPointColor);
synchronized (currentLast) {
float radius = POINT_SIZE / 2.0f;
for (ResultPoint point : currentLast) {
canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), radius, paint);
}
}
}
// Request another update at the animation interval, but only repaint the laser line,
// not the entire viewfinder mask.
postInvalidateDelayed(ANIMATION_DELAY, frame.left - POINT_SIZE, frame.top - POINT_SIZE, frame.right + POINT_SIZE, frame.bottom + POINT_SIZE);
}
}
use of com.google.zxing.ResultPoint in project BarcodeEye by BarcodeEye.
the class ViewfinderView method addPossibleResultPoint.
public void addPossibleResultPoint(ResultPoint point) {
List<ResultPoint> points = possibleResultPoints;
synchronized (points) {
points.add(point);
int size = points.size();
if (size > MAX_RESULT_POINTS) {
// trim it
points.subList(0, size - MAX_RESULT_POINTS / 2).clear();
}
}
}
use of com.google.zxing.ResultPoint in project titanium-barcode by mwaylabs.
the class TitaniumBarcodeActivity method drawResultPoints.
/**
* Superimpose a line for 1D or dots for 2D to highlight the key features of
* the barcode.
*
* @param barcode
* A bitmap of the captured image.
* @param rawResult
* The decoded results which contains the points to draw.
*/
private void drawResultPoints(Bitmap barcode, Result rawResult) {
ResultPoint[] points = rawResult.getResultPoints();
if (points != null && points.length > 0) {
Canvas canvas = new Canvas(barcode);
Paint paint = new Paint();
paint.setColor(BarcodeColor.RESULT_IMAGE_BORDER);
paint.setStrokeWidth(3.0f);
paint.setStyle(Paint.Style.STROKE);
Rect border = new Rect(2, 2, barcode.getWidth() - 2, barcode.getHeight() - 2);
canvas.drawRect(border, paint);
paint.setColor(BarcodeColor.RESULT_POINTS);
if (points.length == 2) {
paint.setStrokeWidth(4.0f);
canvas.drawLine(points[0].getX(), points[0].getY(), points[1].getX(), points[1].getY(), paint);
} else {
paint.setStrokeWidth(10.0f);
for (ResultPoint point : points) {
canvas.drawPoint(point.getX(), point.getY(), paint);
}
}
}
}
Aggregations