1、直接onActivityResult里 ,从Intent data参数中可以取出拍照后缩略图,基本不需要压缩的。
2、是设置保存路径,然后拍完之后直接读取该路径的图片:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String strPath = Environment.getExternalStorageDirectory()+date.getTime();+".jpg";
File myCaptureFile=new File(strPath);
Uri uri = Uri.fromFile(myCaptureFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, 1);
之后直接读取图片进行压缩:
public static Bitmap scalePicture(String filename, int maxWidth,int maxHeight) {
Bitmap bitmap = null;
try {
BitmapFactory.Options opts = new BitmapFactory.Options();
BitmapFactory.decodeFile(filename, opts);
int srcWidth = opts.outWidth;
int srcHeight = opts.outHeight;
int desWidth = 0;
int desHeight = 0;
// 缩放比例
double ratio = 0.0;
if (srcWidth > srcHeight) {
ratio = srcWidth / maxWidth;
desWidth = maxWidth;
desHeight = (int) (srcHeight / ratio);
} else {
ratio = srcHeight / maxHeight;
desHeight = maxHeight;
desWidth = (int) (srcWidth / ratio);
}
// 设置输出宽度、高度
BitmapFactory.Options newOpts = new BitmapFactory.Options();
newOpts.inSampleSize = (int) (ratio) + 1;
newOpts.inJustDecodeBounds = false;
2、是设置保存路径,然后拍完之后直接读取该路径的图片:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String strPath = Environment.getExternalStorageDirect
File myCaptureFile=new File(strPath);
Uri uri = Uri.fromFile(myCaptureFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, 1);
之后直接读取图片进行压缩:
public static Bitmap scalePicture(String filename, int maxWidth,int maxHeight) {
BitmapFactory.Options opts = new BitmapFactory.Options();