Back to project page UniversalImagePick.
The source code is released under:
Apache License
If you think the Android project UniversalImagePick listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.luffyjet.universalimagepick.widget; /*from ww w . j a v a2s . c o m*/ /* * Copyright (C) 2008 ZXing authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.Typeface; import android.util.AttributeSet; import android.view.View; import com.luffyjet.universalimagepick.R; /** * This view is overlaid on top of the camera preview. It adds the viewfinder * rectangle and partial transparency outside it, as well as the laser scanner * animation and result points. * */ public final class ViewfinderView extends View { private static final String TAG = "log"; /** * ????????? */ private static final long ANIMATION_DELAY = 10L; /** * ???? */ private static final int BORDER_WIDTH = 1; /** * ?? */ private Paint mPaint; /** * ???? */ private final int maskColor; /** * ??? */ public Rect mFrame; private static float density; private Bitmap resultBitmap; public ViewfinderView(Context context, AttributeSet attrs) { super(context, attrs); density = context.getResources().getDisplayMetrics().density; mPaint = new Paint(); Resources resources = getResources(); maskColor = resources.getColor(R.color.viewfinder_mask); mFrame = new Rect(50, 250, 450, 650); } @Override public void onDraw(Canvas canvas) { // ??????????? int width = canvas.getWidth(); int height = canvas.getHeight(); mPaint.setColor(maskColor); // ?????????????? canvas.drawRect(0, 0, width, mFrame.top, mPaint);//??? canvas.drawRect(0, mFrame.top, mFrame.left, mFrame.bottom, mPaint);//???? canvas.drawRect(mFrame.right, mFrame.top, width, mFrame.bottom, mPaint);//?????? canvas.drawRect(0, mFrame.bottom, width, height, mPaint);//??? // ?????????? mPaint.setColor(Color.WHITE); canvas.drawRect(mFrame.left, mFrame.top, mFrame.right, mFrame.top + BORDER_WIDTH, mPaint);//???????? canvas.drawRect(mFrame.left, mFrame.top, mFrame.left + BORDER_WIDTH, mFrame.bottom, mPaint);//?????? canvas.drawRect(mFrame.right - BORDER_WIDTH, mFrame.top, mFrame.right, mFrame.bottom, mPaint);//???????? canvas.drawRect(mFrame.left, mFrame.bottom - BORDER_WIDTH, mFrame.right, mFrame.bottom, mPaint);//?? // ???????????????????? postInvalidateDelayed(ANIMATION_DELAY, mFrame.left, mFrame.top, mFrame.right, mFrame.bottom); } public void drawViewfinder() { resultBitmap = null; invalidate(); } /** * Draw a bitmap with the result points highlighted instead of the live * scanning display. * * @param barcode * An image of the decoded barcode. */ public void drawResultBitmap(Bitmap barcode) { resultBitmap = barcode; invalidate(); } }