android.view.SurfaceView类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(175)

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

SurfaceView介绍

暂无

代码示例

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

surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
rawCallback = new PictureCallback() {
  public void onPictureTaken(byte[] data, Camera camera) {
    FileOutputStream outStream = null;
    try {
      outStream = new FileOutputStream(String.format(
          "/sdcard/%d.jpg", System.currentTimeMillis()));
      outStream.write(data);
      outStream.close();
      Log.d("Log", "onPictureTaken - wrote bytes: " + data.length);
    } catch (FileNotFoundException e) {
param = camera.getParameters();
param.setPreviewFrameRate(20);
param.setPreviewSize(176, 144);
camera.setParameters(param);
try {

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

outStream = new FileOutputStream("/sdcard/test.jpg");
     outStream.write(data);
     outStream.close();
   }catch(FileNotFoundException e){
     Log.d("Camera", e.getMessage());
addContentView(mGLSurfaceView, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
 mSurfaceView = new SurfaceView(this);
  addContentView(mSurfaceView, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
 mSurfaceHolder = mSurfaceView.getHolder();
 mSurfaceHolder.addCallback(this);
 mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
 mSurfaceHolder.setFormat(PixelFormat.TRANSLUCENT|LayoutParams.FLAG_BLUR_BEHIND); 
 p.setPreviewSize(arg2, arg3);
 try {
 camera.setPreviewDisplay(arg0);

代码示例来源:origin: jiajunhui/PlayerBase

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  mRenderMeasure.doMeasure(widthMeasureSpec, heightMeasureSpec);
  setMeasuredDimension(mRenderMeasure.getMeasureWidth(),mRenderMeasure.getMeasureHeight());
}

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

SurfaceView sfvTrack = (SurfaceView)findViewById(R.id.sfvTrack);
sfvTrack.setZOrderOnTop(true);    // necessary
SurfaceHolder sfhTrackHolder = sfvTrack.getHolder();
sfhTrackHolder.setFormat(PixelFormat.TRANSPARENT);

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

SurfaceView view = new SurfaceView(this);
c.setPreviewDisplay(view.getHolder());
c.startPreview();
c.takePicture(shutterCallback, rawPictureCallback, jpegPictureCallback);

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

public CameraSourcePreview(Context context, AttributeSet attrs) {
  super(context, attrs);
  mContext = context;
  mStartRequested = false;
  mSurfaceAvailable = false;
  mSurfaceView = new SurfaceView(context);
  mSurfaceView.getHolder().addCallback(new SurfaceCallback());
  addView(mSurfaceView);
}

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

myCamera.setPreviewDisplay(dummy.getHolder());    
myCamera.startPreview(); 
myCamera.takePicture(null, null, getJpegCallback()):
 FileOutputStream fos;
 try {
  fos = new FileOutputStream("test.jpeg");
  fos.write(data);
  fos.close();
 }  catch (IOException e) {

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

mCamera.setPreviewDisplay(sv.getHolder());
    parameters = mCamera.getParameters();
    mCamera.setParameters(parameters);
    mCamera.startPreview();
 } catch (IOException e) { e.printStackTrace(); }
sHolder = sv.getHolder();
sHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        String tar = (sdf.format(cal.getTime()));
        outStream = new FileOutputStream(sd+tar+".jpg");
        outStream.write(data);  outStream.close();

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

SurfaceView surface = new SurfaceView(this);
 Camera camera = Camera.open();
 try {
   camera.setPreviewDisplay(surface.getHolder());
 } catch (IOException e) {
 try {
String dir_path = "";// set your directory path here
   outStream = new FileOutputStream(dir_path+File.separator+image_name+no_pics+".jpg");    
   outStream.write(data);
   outStream.close();
   Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length);
 } catch (FileNotFoundException e) {

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

btncapture=(Button) findViewById(R.id.btncapture);
mSurfaceView = (SurfaceView) findViewById(R.id.surface_camera);
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  public void onClick(View v) {
    mCamera.takePicture(null, null, mPictureCallback);
try {           
  fos = new FileOutputStream(mypath);
  fos.close();
} catch (Exception e) {
  e.printStackTrace();
  int h) {
if (mPreviewRunning) {
  mCamera.stopPreview();
  Camera.Parameters p = mCamera.getParameters();
  p.setPreviewSize(w, h);
  mCamera.setParameters(p);
  try {

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

SurfaceView preview = (SurfaceView) findViewById(R.id.PREVIEW);
SurfaceHolder mHolder = preview.getHolder();
mHolder.addCallback(this);
Camera mCamera = Camera.open();
mCamera.setPreviewDisplay(mHolder);

// Turn on LED  
Parameters params = mCamera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
mCamera.setParameters(params);      
mCamera.startPreview();

...

// Turn off LED
Parameters params = mCamera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
mCamera.setParameters(params);
mCamera.stopPreview();
mCamera.release();

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

super.onActivityCreated(savedInstanceState);
mSurfaceView = (SurfaceView) getView().findViewById(R.id.video_surfaceview);
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  mMediaPlayer = new MediaPlayer();
  AssetFileDescriptor afd = getActivity().getAssets().openFd("sample.3gp");
  mMediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); 
  mMediaPlayer.setDisplay(mSurfaceHolder);
  mMediaPlayer.prepare();
  mMediaPlayer.setOnBufferingUpdateListener(this);

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

holder = mPreview.getHolder();
  holder.setFixedSize(800, 480);
  holder.addCallback(this);
  holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  mp = new MediaPlayer();
  mp.release();
public void surfaceCreated(SurfaceHolder holder) {
  mp.setDisplay(holder);
  play();

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

pause.setVisibility(View.GONE);
if (player != null) {
  if (!player.isPlaying()) {
    pause.setVisibility(View.VISIBLE);
surfaceViewFrame.setOnClickListener(this);
surfaceViewFrame.setClickable(false);
holder = surfaceViewFrame.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
float screenProportion = (float) screenWidth / (float) screenHeight;
android.view.ViewGroup.LayoutParams lp = surfaceViewFrame.getLayoutParams();
  lp.height = screenHeight;
surfaceViewFrame.setLayoutParams(lp);
if (!player.isPlaying()) {
  player.start();         
surfaceViewFrame.setClickable(true);

代码示例来源:origin: blinkinput/blinkinput-android

private void startCamera() {
  try {
    mCamera = Camera.open();
    Camera.Parameters params = mCamera.getParameters();
    List<String> supportedFocusModes = params.getSupportedFocusModes();
    if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
      params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
    } else {
      params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    mFrameHeight = bestSize.height;
    mCamera.setParameters(params);
    mCamera.setPreviewCallbackWithBuffer(this);
    mCamera.setPreviewDisplay(mSurfaceView.getHolder());
    mCamera.startPreview();

代码示例来源:origin: z-chu/HeartRate

@NeedsPermission(Manifest.permission.CAMERA)
void showCamera() {
  mCamera = Camera.open();
  mCamera.setDisplayOrientation(90);
  if (parameters == null) {
    parameters = mCamera.getParameters();
    parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);//打开闪光灯
  }
  if (mPreview == null) {
    mPreview = (SurfaceView) findViewById(R.id.sv_preview);
    mPreviewHolder = mPreview.getHolder();
    mPreviewHolder.addCallback(mSurfaceCallback);
    mPreviewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");
  }
  mWakeLock.acquire();
  if (parameters != null) {
    try {
      mCamera.setPreviewDisplay(mPreviewHolder);
    } catch (IOException e) {
      e.printStackTrace();
    }
    mCamera.setPreviewCallback(mPreviewCallback);
    mCamera.setParameters(parameters);
    mCamera.startPreview();
  }
}

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

surface_holder = surface_view.getHolder();
surface_holder.addCallback(sh_callback);
       mCamera.stopPreview();
       mCamera.release();
       mCamera = null;
          mCamera.setPreviewDisplay(holder);  
       } catch (IOException exception) {  
          mCamera.release();

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

mCamera = Camera.open();
surfaceView = (SurfaceView) findViewById(R.id.surface_camera);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mCamera.unlock();
mrec.setPreviewDisplay(surfaceHolder.getSurface());
mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mrec.setAudioSource(MediaRecorder.AudioSource.MIC); 
mrec.stop();
mrec.release();
mCamera.release();
  mCamera.lock();           // lock camera for later use

代码示例来源:origin: pedroSG94/rtmp-rtsp-stream-client-java

camera = Camera.open(cameraSelect);
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(cameraSelect, info);
isFrontCamera = info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT;
isPortrait = context.getResources().getConfiguration().orientation
  == Configuration.ORIENTATION_PORTRAIT;
Camera.Parameters parameters = camera.getParameters();
parameters.setPreviewSize(width, height);
parameters.setPreviewFormat(imageFormat);
int[] range = adaptFpsRange(fps, parameters.getSupportedPreviewFpsRange());
parameters.setPreviewFpsRange(range[0], range[1]);
camera.setDisplayOrientation(rotation);
if (surfaceView != null) {
 camera.setPreviewDisplay(surfaceView.getHolder());
 camera.addCallbackBuffer(yuvBuffer);
 camera.setPreviewCallbackWithBuffer(this);

代码示例来源:origin: tony-Shx/Swface

if (Camera.getNumberOfCameras() == 1) {
  mCameraId = CameraInfo.CAMERA_FACING_BACK;
  mCamera = Camera.open(mCameraId);
  if (CameraInfo.CAMERA_FACING_FRONT == mCameraId) {
    showTip("前置摄像头已开启,点击可切换");
Parameters params = mCamera.getParameters();
params.setPreviewFormat(ImageFormat.NV21);
params.setPreviewSize(PREVIEW_WIDTH, PREVIEW_HEIGHT);
mCamera.setParameters(params);
  mCamera.setPreviewDisplay(mPreviewSurface.getHolder());
  mCamera.startPreview();
} catch (IOException e) {

相关文章