Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE):访问相机照相
Intent intent=new Intent(MediaStore.ACTION_VIDEO_CAPTURE):跳转到录像的界面
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File("须要存储照片(录像)的文件的名,以及位置")));
Bitmap bitmap=data.getParcelableExtra("data"):直接获取照相数据并转化成bitmap
//图片质量压缩 private Bitmap compressPic1(Bitmap bitmap){ ByteArrayOutputStream ouput=new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG,100,ouput);//压缩质量,言外之意就是越小压缩的越小 int options=100; while(ouput.toByteArray().length/1024>100){ ouput.reset(); options-=1; if(options==1){ break; } bitmap.compress(Bitmap.CompressFormat.JPEG,options,ouput); } bitmap.recycle(); return 压缩后的图片数据; }
//图片比例压缩 private Bitmap compressPic(){ BitmapFactory.Options options=new BitmapFactory.Options(); options.inSampleSize=8; //2的n次幂压缩,图片比列压缩,是原图片的分辨率的1/8 return BitmapFactory.decodeFile(new File("照片的本地地址").toString(),options); }