@Override public void onPreviewFrame(byte[] data, Camera camera) { if (mCurrentFrameNumber == 0) { mLoadingLayout.setVisibility(View.VISIBLE); } else if (mCurrentFrameNumber == 10) { mLoadingLayout.setVisibility(View.GONE); } // 初始化数据 if (!mIsInit) { mAfterTime = System.currentTimeMillis(); if (mAfterTime - mBeforeTime > 10000) { mBeforeTime = mAfterTime; } else if (mCurrentFrameNumber < 10) { // 为了计算平均一帧要多少毫秒,那么就丢失10帧数据来计算平均值 mCurrentFrameNumber++; mDeltaTotal += (mAfterTime - mBeforeTime); } else if (mCameraBinder != null && mCurrentFrameNumber == 10) { mCameraBinder.init( mDeltaTotal / mCurrentFrameNumber, mPreviewSize.width, mPreviewSize.height); mIsInit = true; } mBeforeTime = System.currentTimeMillis(); } if (mCameraBinder != null && mIsInit) { mCameraBinder.add(data, System.currentTimeMillis()); } }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.fab_capture: if (mCameraBinder != null) { long belong = System.currentTimeMillis(); mCameraBinder.capture(belong); mGalleryView.setVisibility(View.GONE); mGalleryLoading.setVisibility(View.VISIBLE); } break; case R.id.btn_gallery: startActivity(new Intent(this, GalleryActivity.class)); break; case R.id.btn_setting: break; } }