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); }