返回顶部
首页 > 资讯 > 精选 >Android实现Camera2预览和拍照效果
  • 905
分享到

Android实现Camera2预览和拍照效果

androidcamera2预览 2023-05-30 18:05:48 905人浏览 薄情痞子
摘要

简介网上对于 Camera2 的介绍有很多,在 GitHub 上也有很多关于 Camera2 的封装库,但是对于那些库,封装性太强,有时候我们仅仅是需要个简简单单的拍照功能而已,因此,自定义一个 Camera 使之变得轻量级那是非常重要的了

简介

网上对于 Camera2 的介绍有很多,在 GitHub 上也有很多关于 Camera2 的封装库,但是对于那些库,封装性太强,有时候我们仅仅是需要个简简单单的拍照功能而已,因此,自定义一个 Camera 使之变得轻量级那是非常重要的了。(本文并非重复造轮子, 而是在于学习 Camera2api 的基本功能, 笔记之。)

学习要点:

使用 Android Camera2 API 的基本功能。
迭代连接到设备的所有相机的特征。
显示相机预览和拍摄照片。

Camera2 API 为连接到 Android 设备的各个相机设备提供了一个界面。 它替代了已弃用的 Camera 类。

  • 使用 getCameraidList 获取所有可用摄像机的列表。 然后,您可以使用 getCameraCharacteristics,并找到适合您需要的最佳相机(前 / 后面,分辨率等)。
  • 创建一个 CameraDevice.StateCallback 的实例并打开相机。 当相机打开时,准备开始相机预览。
  • 使用 TextureView 显示相机预览。 创建一个 CameraCaptureSession 并设置一个重复的 CaptureRequest。
  • 静像拍摄需要几个步骤。 首先,需要通过更新相机预览的 CaptureRequest 来定相机的焦点。
  • 然后,以类似的方式,需要运行一个预捕获序列。之后,它准备拍摄一张照片。 创建一个新的 CaptureRequest 并调用 [capture] 。

完成后,别忘了解锁焦点。

实现效果

Android实现Camera2预览和拍照效果环境

SDK>21

Camera2 类图

Android实现Camera2预览和拍照效果

Android实现Camera2预览和拍照效果

代码实现

CameraPreview.java

public class CameraPreview extends TextureView {  private static final String TAG = "CameraPreview";  private static final SparseIntArray ORIENTATIONS = new SparseIntArray();//从屏幕旋转转换为JPEG方向  private static final int MAX_PREVIEW_WIDTH = 1920;//Camera2 API 保证的最大预览宽高  private static final int MAX_PREVIEW_HEIGHT = 1080;  private static final int STATE_PREVIEW = 0;//显示相机预览  private static final int STATE_WAITING_LOCK = 1;//焦点锁定中  private static final int STATE_WAITING_PRE_CAPTURE = 2;//拍照中  private static final int STATE_WAITING_NON_PRE_CAPTURE = 3;//其它状态  private static final int STATE_PICTURE_TAKEN = 4;//拍照完毕  private int mState = STATE_PREVIEW;  private int mRatioWidth = 0, mRatioHeight = 0;  private int mSensorOrientation;  private boolean mFlashSupported;  private Semaphore mCameraopenCloseLock = new Semaphore(1);//使用信号量 Semaphore 进行多线程任务调度  private Activity activity;  private File mFile;  private HandlerThread mBackgroundThread;  private Handler mBackgroundHandler;  private Size mPreviewSize;  private String mCameraId;  private CameraDevice mCameraDevice;  private CaptureRequest.Builder mPreviewRequestBuilder;  private CaptureRequest mPreviewRequest;  private CameraCaptureSession mCaptureSession;  private ImageReader mImageReader;  static {    ORIENTATIONS.append(Surface.ROTATION_0, 90);    ORIENTATIONS.append(Surface.ROTATION_90, 0);    ORIENTATIONS.append(Surface.ROTATION_180, 270);    ORIENTATIONS.append(Surface.ROTATION_270, 180);  }  public CameraPreview(Context context) {    this(context, null);  }  public CameraPreview(Context context, AttributeSet attrs) {    this(context, attrs, 0);  }  public CameraPreview(Context context, AttributeSet attrs, int defStyleAttr) {    super(context, attrs, defStyleAttr);    mFile = new File(getContext().getExternalFilesDir(null), "pic.jpg");  }  @Override  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {    super.onMeasure(widthMeasureSpec, heightMeasureSpec);    int width = MeasureSpec.getSize(widthMeasureSpec);    int height = MeasureSpec.getSize(heightMeasureSpec);    if (0 == mRatioWidth || 0 == mRatioHeight) {      setMeasuredDimension(width, height);    } else {      if (width < height * mRatioWidth / mRatioHeight) {        setMeasuredDimension(width, width * mRatioHeight / mRatioWidth);      } else {        setMeasuredDimension(height * mRatioWidth / mRatioHeight, height);      }    }  }  public void onResume(Activity activity) {    this.activity = activity;    startBackgroundThread();    //当Activity或Fragment OnResume()时,可以冲洗打开一个相机并开始预览,否则,这个Surface已经准备就绪    if (this.isAvailable()) {      openCamera(this.getWidth(), this.getHeight());    } else {      this.setSurfaceTextureListener(mSurfaceTextureListener);    }  }  public void onPause() {    closeCamera();    stopBackgroundThread();  }  public void setOutPutDir(File file) {    this.mFile = file;  }  public void setAspectRatio(int width, int height) {    if (width < 0 || height < 0) {      throw new IllegalArgumentException("Size can't be negative");    }    mRatioWidth = width;    mRatioHeight = height;    requestLayout();  }  public void setAutoFlash(CaptureRequest.Builder requestBuilder) {    if (mFlashSupported) {      requestBuilder.set(CaptureRequest.CONTROL_AE_MODE,          CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);    }  }  public void takePicture() {    lockFocus();  }  private void startBackgroundThread() {    mBackgroundThread = new HandlerThread("CameraBackground");    mBackgroundThread.start();    mBackgroundHandler = new Handler(mBackgroundThread.getLooper());  }  private void stopBackgroundThread() {    mBackgroundThread.quitSafely();    try {      mBackgroundThread.join();      mBackgroundThread = null;      mBackgroundHandler = null;    } catch (InterruptedException e) {      e.printStackTrace();    }  }    private final TextureView.SurfaceTextureListener mSurfaceTextureListener = new TextureView.SurfaceTextureListener() {    @Override    public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) {      openCamera(width, height);    }    @Override    public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) {      configureTransfORM(width, height);    }    @Override    public boolean onSurfaceTextureDestroyed(SurfaceTexture texture) {      return true;    }    @Override    public void onSurfaceTextureUpdated(SurfaceTexture texture) {    }  };    private final CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() {    @Override    public void onOpened(@NonNull CameraDevice cameraDevice) {      mCameraOpenCloseLock.release();      Log.d(TAG, "相机已打开");      mCameraDevice = cameraDevice;      createCameraPreviewSession();    }    @Override    public void onDisconnected(@NonNull CameraDevice cameraDevice) {      mCameraOpenCloseLock.release();      cameraDevice.close();      mCameraDevice = null;    }    @Override    public void onError(@NonNull CameraDevice cameraDevice, int error) {      mCameraOpenCloseLock.release();      cameraDevice.close();      mCameraDevice = null;      if (null != activity) {        activity.finish();      }    }  };    private CameraCaptureSession.CaptureCallback mCaptureCallback = new CameraCaptureSession.CaptureCallback() {    private void process(CaptureResult result) {      switch (mState) {        case STATE_PREVIEW: {          break;        }        case STATE_WAITING_LOCK: {          Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);          if (afState == null) {            captureStillPicture();          } else if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState ||              CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) {            Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);            if (aeState == null || aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) {              mState = STATE_PICTURE_TAKEN;              captureStillPicture();            } else {              runPreCaptureSequence();            }          }          break;        }        case STATE_WAITING_PRE_CAPTURE: {          Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);          if (aeState == null ||              aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE ||              aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {            mState = STATE_WAITING_NON_PRE_CAPTURE;          }          break;        }        case STATE_WAITING_NON_PRE_CAPTURE: {          Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);          if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) {            mState = STATE_PICTURE_TAKEN;            captureStillPicture();          }          break;        }      }    }    @Override    public void onCaptureProgressed(@NonNull CameraCaptureSession session,                    @NonNull CaptureRequest request,                    @NonNull CaptureResult partialResult) {      process(partialResult);    }    @Override    public void onCaptureCompleted(@NonNull CameraCaptureSession session,                    @NonNull CaptureRequest request,                    @NonNull TotalCaptureResult result) {      process(result);    }  };    private void configureTransform(int viewWidth, int viewHeight) {    if (null == mPreviewSize || null == activity) {      return;    }    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();    Matrix matrix = new Matrix();    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());    float centerX = viewRect.centerX();    float centerY = viewRect.centerY();    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {      bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());      matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);      float scale = Math.max(          (float) viewHeight / mPreviewSize.getHeight(),          (float) viewWidth / mPreviewSize.getWidth());      matrix.postScale(scale, scale, centerX, centerY);      matrix.postRotate(90 * (rotation - 2), centerX, centerY);    } else if (Surface.ROTATION_180 == rotation) {      matrix.postRotate(180, centerX, centerY);    }    this.setTransform(matrix);  }    private void openCamera(int width, int height) {    setUpCameraOutputs(width, height);    configureTransform(width, height);    CameraManager manager = (CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE);    try {      if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {        throw new RuntimeException("Time out waiting to lock camera opening.");      }      if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {        // TODO: Consider calling        //  ActivityCompat#requestPermissions        // here to request the missing permissions, and then overriding        //  public void onRequestPermissionsResult(int requestCode, String[] permissions,        //                     int[] grantResults)        // to handle the case where the user grants the permission. See the documentation        // for ActivityCompat#requestPermissions for more details.        return;      }      manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler);    } catch (CameraAccessException e) {      e.printStackTrace();    } catch (InterruptedException e) {      throw new RuntimeException("Interrupted while trying to lock camera opening.", e);    }  }    private void closeCamera() {    try {      mCameraOpenCloseLock.acquire();      if (null != mCaptureSession) {        mCaptureSession.close();        mCaptureSession = null;      }      if (null != mCameraDevice) {        mCameraDevice.close();        mCameraDevice = null;      }      if (null != mImageReader) {        mImageReader.close();        mImageReader = null;      }    } catch (InterruptedException e) {      throw new RuntimeException("Interrupted while trying to lock camera closing.", e);    } finally {      mCameraOpenCloseLock.release();    }  }    @SuppressWarnings("SuspiciousNameCombination")  private void setUpCameraOutputs(int width, int height) {    CameraManager manager = (CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE);    try {      for (String cameraId : manager.getCameraIdList()) {        CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);        // 在这个例子中不使用前置摄像头        Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);        if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {          continue;        }        StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);        if (map == null) {          continue;        }        Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),            new CompareSizesByArea());        mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(),            ImageFormat.JPEG, 2);        mImageReader.setOnImageAvailableListener(            mOnImageAvailableListener, mBackgroundHandler);        int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation();        // noinspection ConstantConditions        mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);        boolean swappedDimensions = false;        switch (displayRotation) {          case Surface.ROTATION_0:          case Surface.ROTATION_180:            if (mSensorOrientation == 90 || mSensorOrientation == 270) {              swappedDimensions = true;            }            break;          case Surface.ROTATION_90:          case Surface.ROTATION_270:            if (mSensorOrientation == 0 || mSensorOrientation == 180) {              swappedDimensions = true;            }            break;          default:            Log.e(TAG, "Display rotation is invalid: " + displayRotation);        }        Point displaySize = new Point();        activity.getWindowManager().getDefaultDisplay().getSize(displaySize);        int rotatedPreviewWidth = width;        int rotatedPreviewHeight = height;        int maxPreviewWidth = displaySize.x;        int maxPreviewHeight = displaySize.y;        if (swappedDimensions) {          rotatedPreviewWidth = height;          rotatedPreviewHeight = width;          maxPreviewWidth = displaySize.y;          maxPreviewHeight = displaySize.x;        }        if (maxPreviewWidth > MAX_PREVIEW_WIDTH) {          maxPreviewWidth = MAX_PREVIEW_WIDTH;        }        if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) {          maxPreviewHeight = MAX_PREVIEW_HEIGHT;        }        mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),            rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth,            maxPreviewHeight, largest);        int orientation = getResources().getConfiguration().orientation;        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {          setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight());        } else {          setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth());        }        Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);        mFlashSupported = available == null ? false : available;        mCameraId = cameraId;        return;      }    } catch (CameraAccessException e) {      e.printStackTrace();    } catch (NullPointerException e) {      Log.e(TAG, "设备不支持Camera2");    }  }    private static Size chooseOptimalSize(Size[] choices, int textureViewWidth, int textureViewHeight,                     int maxWidth, int maxHeight, Size aspectRatio) {    List<Size> bigEnough = new ArrayList<>();    List<Size> notBigEnough = new ArrayList<>();    int w = aspectRatio.getWidth();    int h = aspectRatio.getHeight();    for (Size option : choices) {      if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight &&          option.getHeight() == option.getWidth() * h / w) {        if (option.getWidth() >= textureViewWidth &&            option.getHeight() >= textureViewHeight) {          bigEnough.add(option);        } else {          notBigEnough.add(option);        }      }    }    if (bigEnough.size() > 0) {      return Collections.min(bigEnough, new CompareSizesByArea());    } else if (notBigEnough.size() > 0) {      return Collections.max(notBigEnough, new CompareSizesByArea());    } else {      Log.e(TAG, "Couldn't find any suitable preview size");      return choices[0];    }  }    private void createCameraPreviewSession() {    try {      SurfaceTexture texture = this.getSurfaceTexture();      assert texture != null;      // 将默认缓冲区的大小配置为想要的相机预览的大小      texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());      Surface surface = new Surface(texture);      mPreviewRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);      mPreviewRequestBuilder.addTarget(surface);      // 我们创建一个 CameraCaptureSession 来进行相机预览      mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),          new CameraCaptureSession.StateCallback() {            @Override            public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {              if (null == mCameraDevice) {                return;              }              // 会话准备好后,我们开始显示预览              mCaptureSession = cameraCaptureSession;              try {                mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,                    CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);                setAutoFlash(mPreviewRequestBuilder);                mPreviewRequest = mPreviewRequestBuilder.build();                mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler);              } catch (CameraAccessException e) {                e.printStackTrace();              }            }            @Override            public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {            }          }, null);    } catch (CameraAccessException e) {      e.printStackTrace();    }  }    private int getOrientation(int rotation) {    return (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360;  }    private void lockFocus() {    try {      // 如何通知相机锁定焦点      mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);      // 通知mCaptureCallback等待锁定      mState = STATE_WAITING_LOCK;      mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);    } catch (CameraAccessException e) {      e.printStackTrace();    }  }    private void unlockFocus() {    try {      mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,          CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);      setAutoFlash(mPreviewRequestBuilder);      mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,          mBackgroundHandler);      mState = STATE_PREVIEW;      mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,          mBackgroundHandler);    } catch (CameraAccessException e) {      e.printStackTrace();    }  }    private void captureStillPicture() {    try {      if (null == activity || null == mCameraDevice) {        return;      }      final CaptureRequest.Builder captureBuilder =          mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);      captureBuilder.addTarget(mImageReader.getSurface());      captureBuilder.set(CaptureRequest.CONTROL_AF_MODE,          CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);      setAutoFlash(captureBuilder);      // 方向      int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();      captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation));      CameraCaptureSession.CaptureCallback captureCallback          = new CameraCaptureSession.CaptureCallback() {        @Override        public void onCaptureCompleted(@NonNull CameraCaptureSession session,                        @NonNull CaptureRequest request,                        @NonNull TotalCaptureResult result) {          Toast.makeText(getContext(), "Saved: " + mFile, Toast.LENGTH_SHORT).show();          Log.d(TAG, mFile.toString());          unlockFocus();        }      };      mCaptureSession.stopRepeating();      mCaptureSession.abortCaptures();      mCaptureSession.capture(captureBuilder.build(), captureCallback, null);    } catch (CameraAccessException e) {      e.printStackTrace();    }  }    private void runPreCaptureSequence() {    try {      // 设置拍照参数请求      mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,          CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);      mState = STATE_WAITING_PRE_CAPTURE;      mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);    } catch (CameraAccessException e) {      e.printStackTrace();    }  }    private static class CompareSizesByArea implements Comparator<Size> {    @Override    public int compare(Size lhs, Size rhs) {      return Long.signum((long) lhs.getWidth() * lhs.getHeight() -          (long) rhs.getWidth() * rhs.getHeight());    }  }    private final ImageReader.OnImageAvailableListener mOnImageAvailableListener      = new ImageReader.OnImageAvailableListener() {    @Override    public void onImageAvailable(ImageReader reader) {      mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(), mFile));    }  };    private static class ImageSaver implements Runnable {    private final Image mImage;    private final File mFile;    ImageSaver(Image image, File file) {      mImage = image;      mFile = file;    }    @Override    public void run() {      ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();      byte[] bytes = new byte[buffer.remaining()];      buffer.get(bytes);      FileOutputStream output = null;      try {        output = new FileOutputStream(mFile);        output.write(bytes);      } catch (IOException e) {        e.printStackTrace();      } finally {        mImage.close();        if (null != output) {          try {            output.close();          } catch (IOException e) {            e.printStackTrace();          }        }      }    }  }}

--结束END--

本文标题: Android实现Camera2预览和拍照效果

本文链接: https://lsjlt.com/news/220499.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
  • Android实现Camera2预览和拍照效果
    简介网上对于 Camera2 的介绍有很多,在 Github 上也有很多关于 Camera2 的封装库,但是对于那些库,封装性太强,有时候我们仅仅是需要个简简单单的拍照功能而已,因此,自定义一个 Camera 使之变得轻量级那是非常重要的了...
    99+
    2023-05-30
    android camera2 预览
  • Android Camera2-预览、拍照、录像流程
    一、Camera2实现预览、拍照、录像三大基础功能的流程框架图 Camera2关键几个类: CameraManager 管理手机上的所有摄像头设备。管理手机上的所有摄像头设备,它的作用主要是获取摄像头列表和打开(openCamera)指定...
    99+
    2023-09-01
    android
  • 十分钟实现 Android Camera2 相机预览
    1. 前言 因为工作中要使用Android Camera2 API,但因为Camera2比较复杂,网上资料也比较乱,有一定入门门槛,所以花了几天时间系统研究了下,并在CSDN上记录了下,希望能帮助到更...
    99+
    2023-10-26
    android 相机 Camera2 音视频 预览
  • Android实现拍照及图片显示效果
    本文实例为大家分享了Android拍照及图片显示的具体代码,供大家参考,具体内容如下 1、功能声明 当应用需要使用相机、NFC等外设时,需要在AndroidManifest...
    99+
    2022-06-06
    图片 Android
  • android 拍照和上传的实现代码
    代码如下:import java.io.ByteArrayOutputStream;   import java.io.File;  ...
    99+
    2022-06-06
    Android
  • Android实现图片点击预览效果(zoom动画)
    参考:https://developer.android.google.cn/training/animation/zoom.html 1.创建Views 下面的布局包括了你想...
    99+
    2022-06-06
    图片 zoom Android
  • Android实现拍照截图功能
    本文将向大家展示如何拍照截图。 先看看效果图: 拍照截图有点儿特殊,要知道,现在的Android智能手机的摄像头都是几百万的像素,拍出来的图片都是非常大的。因此,我们不能像对...
    99+
    2022-06-06
    Android
  • Android实现手机拍照功能
    本文实例为大家讲解如何轻松实现Android手机拍照功能,分享给大家供大家参考。具体如下: 一、布局文件main.xml <?xml version="1.0...
    99+
    2022-06-06
    手机 Android
  • Android webview实现拍照的方法
    Android webview实现拍照的方法 html <div id="pnlVideo1"> <input type="hidden" name="imgNric1" id="im...
    99+
    2023-05-30
    android webview 拍照
  • Android SurfaceView拍照录像实现方法
    Surface的拍照实现也是很简单,一个小demo就可以把流程看懂了。 话不多说,直接上代码 布局文件 <SurfaceView android:layou...
    99+
    2022-06-06
    方法 surfaceview Android
  • Android实现控制摄像头拍照
    现在的手机一般都会提供相机功能,有些相机的镜头甚至支持1300万以上像素,有些甚至支持独立对焦、光学变焦这些只有单反才有的功能,甚至有些手机直接宣传可以拍到星星。可以说手机已经变成了...
    99+
    2024-04-02
  • Android中怎么实现拍照功能
    这期内容当中小编将会给大家带来有关Android中怎么实现拍照功能,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。解析:1)判断是否有摄像头checkCameraHardware(this) 2)获得相机c...
    99+
    2023-05-30
    android
  • Android Camera实现毫秒级拍照实例
    我们知道自定义Camera需要以下几步 打开相机,即实例化Camera对象,Camera camera = Camera.open(); 设置Camera的相关参数,Camera.Parameters parameter...
    99+
    2023-05-31
    android camera 拍照
  • Android实现本地图片选择及预览缩放效果
    在做项目时经常会遇到选择本地图片的需求,以前都是懒得写直接调用系统方法来选择图片,但是这样并不能实现多选效果,最近又遇到了,所以还是写一个demo好了,以后也方便使用。还是首先...
    99+
    2022-06-06
    选择 图片 地图 Android
  • Android实现拍照截取和相册图片截取
    关于拍照截取和相册截取,看了网上很多资料,自己整理了一份比较详细的,供有需要的人参考 1  拍照 原理就是通过intent调用系统的相机,拍完照在回调进行操作,成功...
    99+
    2022-06-06
    图片 Android
  • Android 实现调用系统照相机拍照和录像的功能
    本文实现android系统照相机的调用来拍照 项目的布局相当简单,只有一个Button: <RelativeLayout xmlns:android="http://s...
    99+
    2022-06-06
    调用 系统 相机 Android
  • Android实现拍照添加时间水印
    本文实例为大家分享了Android实现拍照添加时间水印的具体代码,供大家参考,具体内容如下 效果如下图 : 1、拍照 // 非空判断 拍照  if (mCamera0 != nul...
    99+
    2024-04-02
  • Vue+SSM实现图片上传预览效果
    现在的需求是:有一个上传文件按钮,当我们点击按钮时,可以选择需要上传的文件,确定后图片显示在界面上。 说明:本项目前端使用的Vue,后台用的SSM搭建的,服务器是Tomcat,数据库...
    99+
    2024-04-02
  • Android中怎么利用ViewPager实现图片滑动预览效果
    本篇文章给大家分享的是有关Android中怎么利用ViewPager实现图片滑动预览效果,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。xml代码:<xml ve...
    99+
    2023-05-30
    android viewpager
  • android预加载效果怎么实现
    实现Android预加载效果可以使用以下几种方法:1. 使用AsyncTask:在Activity或Fragment中创建一个Asy...
    99+
    2023-08-17
    android
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作