android.hardware.Camera.setPreviewTexture()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(771)

本文整理了Java中android.hardware.Camera.setPreviewTexture()方法的一些代码示例,展示了Camera.setPreviewTexture()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Camera.setPreviewTexture()方法的具体详情如下:
包路径:android.hardware.Camera
类名称:Camera
方法名:setPreviewTexture

Camera.setPreviewTexture介绍

暂无

代码示例

代码示例来源:origin: journeyapps/zxing-android-embedded

public void setPreview(Camera camera) throws IOException {
    if(surfaceHolder != null) {
      camera.setPreviewDisplay(surfaceHolder);
    } else {
      camera.setPreviewTexture(surfaceTexture);
    }
  }
}

代码示例来源:origin: LaiFeng-Android/SopCastComponent

public void setSurfaceTexture(SurfaceTexture texture) {
  mTexture = texture;
  if(mState == State.PREVIEW && mCameraDevice != null && mTexture != null) {
    try {
      mCameraDevice.setPreviewTexture(mTexture);
    } catch (IOException e) {
      releaseCamera();
    }
  }
}

代码示例来源:origin: stackoverflow.com

mCamera.setPreviewTexture(surface);
} catch (IOException t) {}

代码示例来源:origin: LaiFeng-Android/SopCastComponent

public synchronized void startPreview() {
  if(mState != State.OPENED) {
    return;
  }
  if(mCameraDevice == null) {
    return;
  }
  if(mTexture == null) {
    return;
  }
  try {
    mCameraDevice.setPreviewTexture(mTexture);
    mCameraDevice.startPreview();
    mState = State.PREVIEW;
  } catch (Exception e) {
    releaseCamera();
    e.printStackTrace();
  }
}

代码示例来源:origin: vondear/RxTool

@SuppressLint("NewApi")
void setUpPreview() {
  try {
    if (mPreview.getOutputClass() == SurfaceHolder.class) {
      final boolean needsToStopPreview = mShowingPreview && Build.VERSION.SDK_INT < 14;
      if (needsToStopPreview) {
        mCamera.stopPreview();
      }
      mCamera.setPreviewDisplay(mPreview.getSurfaceHolder());
      if (needsToStopPreview) {
        mCamera.startPreview();
      }
    } else {
      mCamera.setPreviewTexture((SurfaceTexture) mPreview.getSurfaceTexture());
    }
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: cats-oss/android-gpuimage

@Override
  public void run() {
    int[] textures = new int[1];
    GLES20.glGenTextures(1, textures, 0);
    surfaceTexture = new SurfaceTexture(textures[0]);
    try {
      camera.setPreviewTexture(surfaceTexture);
      camera.setPreviewCallback(GPUImageRenderer.this);
      camera.startPreview();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
});

代码示例来源:origin: google/cameraview

@SuppressLint("NewApi")
void setUpPreview() {
  try {
    if (mPreview.getOutputClass() == SurfaceHolder.class) {
      final boolean needsToStopPreview = mShowingPreview && Build.VERSION.SDK_INT < 14;
      if (needsToStopPreview) {
        mCamera.stopPreview();
      }
      mCamera.setPreviewDisplay(mPreview.getSurfaceHolder());
      if (needsToStopPreview) {
        mCamera.startPreview();
      }
    } else {
      mCamera.setPreviewTexture((SurfaceTexture) mPreview.getSurfaceTexture());
    }
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: stackoverflow.com

mCamera.setPreviewTexture(surface);
} catch (IOException t) {

代码示例来源:origin: googlesamples/android-vision

mCamera.setPreviewTexture(null);

代码示例来源:origin: googlesamples/android-vision

camera.setPreviewTexture(null);

代码示例来源:origin: googlesamples/android-vision

mCamera.setPreviewTexture(null);

代码示例来源:origin: googlesamples/android-vision

/**
 * Opens the camera and starts sending preview frames to the underlying detector.  The preview
 * frames are not displayed.
 *
 * @throws IOException if the camera's preview texture or display could not be initialized
 */
@RequiresPermission(Manifest.permission.CAMERA)
public CameraSource start() throws IOException {
  synchronized (mCameraLock) {
    if (mCamera != null) {
      return this;
    }
    mCamera = createCamera();
    // SurfaceTexture was introduced in Honeycomb (11), so if we are running and
    // old version of Android. fall back to use SurfaceView.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      mDummySurfaceTexture = new SurfaceTexture(DUMMY_TEXTURE_NAME);
      mCamera.setPreviewTexture(mDummySurfaceTexture);
    } else {
      mDummySurfaceView = new SurfaceView(mContext);
      mCamera.setPreviewDisplay(mDummySurfaceView.getHolder());
    }
    mCamera.startPreview();
    mProcessingThread = new Thread(mFrameProcessor);
    mFrameProcessor.setActive(true);
    mProcessingThread.start();
  }
  return this;
}

代码示例来源:origin: googlesamples/android-vision

/**
 * Opens the camera and starts sending preview frames to the underlying detector.  The preview
 * frames are not displayed.
 *
 * @throws IOException if the camera's preview texture or display could not be initialized
 */
@RequiresPermission(Manifest.permission.CAMERA)
public CameraSource start() throws IOException {
  synchronized (cameraLock) {
    if (camera != null) {
      return this;
    }
    camera = createCamera();
    // SurfaceTexture was introduced in Honeycomb (11), so if we are running and
    // old version of Android. fall back to use SurfaceView.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      dummySurfaceTexture = new SurfaceTexture(DUMMY_TEXTURE_NAME);
      camera.setPreviewTexture(dummySurfaceTexture);
    } else {
      dummySurfaceView = new SurfaceView(context);
      camera.setPreviewDisplay(dummySurfaceView.getHolder());
    }
    camera.startPreview();
    processingThread = new Thread(frameProcessor);
    frameProcessor.setActive(true);
    processingThread.start();
  }
  return this;
}

代码示例来源:origin: googlesamples/android-vision

/**
 * Opens the camera and starts sending preview frames to the underlying detector.  The preview
 * frames are not displayed.
 *
 * @throws IOException if the camera's preview texture or display could not be initialized
 */
@RequiresPermission(Manifest.permission.CAMERA)
public CameraSource start() throws IOException {
  synchronized (mCameraLock) {
    if (mCamera != null) {
      return this;
    }
    mCamera = createCamera();
    // SurfaceTexture was introduced in Honeycomb (11), so if we are running and
    // old version of Android. fall back to use SurfaceView.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      mDummySurfaceTexture = new SurfaceTexture(DUMMY_TEXTURE_NAME);
      mCamera.setPreviewTexture(mDummySurfaceTexture);
    } else {
      mDummySurfaceView = new SurfaceView(mContext);
      mCamera.setPreviewDisplay(mDummySurfaceView.getHolder());
    }
    mCamera.startPreview();
    mProcessingThread = new Thread(mFrameProcessor);
    mFrameProcessor.setActive(true);
    mProcessingThread.start();
  }
  return this;
}

代码示例来源:origin: Rajawali/Rajawali

protected void add() throws TextureException {
  int[] textures = new int[1];
  GLES20.glGenTextures(1, textures, 0);
  int textureId = textures[0];
  GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureId);
  GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES,
    GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
  GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES,
    GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
  GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES,
    GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
  GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES,
    GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
  setTextureId(textureId);
  mSurfaceTexture = new SurfaceTexture(textureId);
  if (mMediaPlayer != null) {
    mSurface = new Surface(mSurfaceTexture);
    mMediaPlayer.setSurface(mSurface);
  } else if (mCamera != null) {
    try {
      mSurfaceTexture.setOnFrameAvailableListener(mOnFrameAvailableListener);
      mCamera.setPreviewTexture(mSurfaceTexture);
    } catch (IOException e) {
      throw new TextureException(e);
    }
  } else if (mSurfaceListener != null) {
    mSurfaceListener.setSurface(new Surface(mSurfaceTexture));
  }
}

代码示例来源:origin: doggycoder/AndroidOpenGLDemo

public void setPreviewTexture(SurfaceTexture texture){
  if(mCamera!=null){
    try {
      mCamera.setPreviewTexture(texture);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: doggycoder/AndroidOpenGLDemo

public void setPreviewTexture(SurfaceTexture texture){
  if(mCamera!=null){
    try {
      mCamera.setPreviewTexture(texture);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: nekocode/CameraFilter

camera.setPreviewTexture(cameraSurfaceTexture);
  camera.startPreview();
} catch (IOException ioe) {

代码示例来源:origin: doggycoder/AndroidOpenGLDemo

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
  if (mCamera != null) {
    mCamera.stopPreview();
    mCamera.release();
    mCamera = null;
  }
  mCamera = Camera.open(cameraId);
  mController.setImageDirection(cameraId);
  Camera.Size size = mCamera.getParameters().getPreviewSize();
  mController.setDataSize(size.height, size.width);
  try {
    mCamera.setPreviewTexture(mController.getTexture());
    mController.getTexture().setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() {
      @Override
      public void onFrameAvailable(SurfaceTexture surfaceTexture) {
        mController.requestRender();
      }
    });
  } catch (IOException e) {
    e.printStackTrace();
  }
  mCamera.startPreview();
}

代码示例来源:origin: ChillingVan/AndroidInstantVideo

@Override
public void setPreview(SurfaceTexture surfaceTexture) {
  try {
    camera.setPreviewTexture(surfaceTexture);
  } catch (IOException e) {
    e.printStackTrace();
  }
}

相关文章