android 视频和图片预览

展开阅读全文

android获取预览图片怎么获取一张图片

06-19

public class MainActivity extends AppCompatActivity { private SurfaceView sv_camera_surfaceview; private android.hardware.Camera camera; private SurfaceHolder surfaceholder; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sv_camera_surfaceview = (SurfaceView) findViewById(R.id.sv_camera_sufaceview); sv_camera_surfaceview.getHolder().addCallback(new SurfaceHolder.Callback() { @Override public void surfaceCreated(SurfaceHolder holder) { camera = Camera.open();//开启摄像头 } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Camera.Parameters parameters = camera.getParameters(); parameters.setPictureFormat(ImageFormat.NV21); parameters.setPreviewFormat(ImageFormat.NV21); //parameters.setPictureFormat(ImageFormat.NV21); //设置格式 //parameters.getSupportedPictureSizes(); //parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);//自动聚焦 //parameters.setPreviewSize(900,240); /* WindowManager windowManager = getWindowManager(); Display display = windowManager.getDefaultDisplay(); int screenWidth = screenWidth = display.getWidth(); int screenHeight = screenHeight = display.getHeight(); parameters.setPictureSize(screenWidth, screenHeight);*/ //camera.Size(100,50); // parameters.setPictureSize(500,80); // parameters.set("YCbCr_420_SP",100); //List<android.support.annotation.Size>picturesize=camera.getParameters().getSupportedPictureSizes(); // List<Camera.Size> picturesize=camera.getParameters().getSupportedPictureSizes(); /*List<Camera.Size>picturesize=camera.getParameters().getSupportedPictureSizes(); List<Camera.Size>previewsize=camera.getParameters().getSupportedPreviewSizes(); List<Integer> previewformats=camera.getParameters().getSupportedPreviewFormats(); List<Integer> previewframerates=camera.getParameters().getSupportedPreviewFrameRates(); //Lise<Integer> Size size=null; for (int i=0 ;i<picturesize.size();i++){ size= (Size) picturesize.get(i); } for (int i=0;i<previewsize.size();i++){ size= (Size) previewsize.get(i); } Integer in=null; for (int i=0;i<previewformats.size();i++){ in=previewformats.get(i); } parameters.setPictureSize(1080,1920); //camera.setParameters(parameters); // camera.startPreview(); // int previewWidth; // int previewHeight; //List<Camera.Size>previerSizes=camera.getParameters().getPreviewSize();*/ List<Camera.Size> pictureSize = camera.getParameters().getSupportedPictureSizes(); List<Camera.Size> previewsize = camera.getParameters().getSupportedPreviewSizes(); //List<int []> range=parameters.getSupportedPreviewFpsRange(); Camera.Size size; // size.width=width; // size.height=height; for (int i = 0; i < pictureSize.size(); i++) { size = pictureSize.get(i); } for (int i = 0; i < previewsize.size(); i++) { size = previewsize.get(i); } /*for (int j=0;j<range.size();j++){ int [] r=range.get(j); }*/ //parameters.setPreviewFpsRange(30,30); parameters.setPictureSize(192,1080); parameters.setPreviewSize(1920,1080); //parameters.setPreviewFrameRate(30000); camera.setDisplayOrientation(0);//角度 camera.setParameters(parameters); try { camera.setPreviewDisplay(sv_camera_surfaceview.getHolder());//实时预览 camera.startPreview(); /// /开启预览 } catch (IOException e) { e.printStackTrace(); } } @Override public void surfaceDestroyed(SurfaceHolder holder) { } }); } public void takephoto(View view) { camera.setPreviewCallback(new Camera.PreviewCallback() { @Override public void onPreviewFrame(byte[] data, Camera camera) { //byte a=data[0]; //if (data.length<=1) { //System.arraycopy(data, 0, ImageFormat.NV21, 0, data.length); FileOutputStream fileoutputstream ; try { fileoutputstream = new FileOutputStream(String.format("sdcard/DCIM/camera/" + System.currentTimeMillis() + "12")); fileoutputstream.write(data); fileoutputstream.close(); //YuvImage yuvImage=new YuvImage(data,ImageFormat.NV21,1080,1920,null); //Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); } catch (IOException e) { e.printStackTrace(); } } }); } } 现在每次点击一次拍照都是获得很多张照片怎么只获得点击拍照最近的照片 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览