安卓app调用系统照相功能拍出的图片在相册里面看不到,但在文件中看得到
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
String sdStatus = Environment.getExternalStorageState();
switch (requestCode) {
case 1:
if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) {
Log.i("内存卡错误", "请检查您的内存卡");
} else {
File photo = new File(photoName);
if(photo.exists())
{
BitmapFactory.Options op = new BitmapFactory.Options();
// 设置图片的大小
Bitmap bitMap = BitmapFactory.decodeFile(photoName);
int width = bitMap.getWidth();
int height = bitMap.getHeight();
// 设置想要的大小
int newWidth = width;
int newHeight = height;
// 计算缩放比例
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 取得想要缩放的matrix参数
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片
bitMap = Bitmap.createBitmap(bitMap, 0, 0, width, height,
matrix, true);
// canvas.drawBitmap(bitMap, 0, 0, paint)
// 防止内存溢出
op.inSampleSize = 1; // 这个数字越大,图片大小越小.
Bitmap pic = null;
pic = BitmapFactory.decodeFile(photoName, op);
img_photo.setImageBitmap(pic); // 这个ImageView是拍照完成后显示图片
FileOutputStream b = null;
;
try {
b = new FileOutputStream(photoName);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if (pic != null) {
pic.compress(Bitmap.CompressFormat.JPEG, 50, b);
uploadFile=photoName;
ContentResolver cr = getContentResolver();
try {
MediaStore.Images.Media.insertImage(cr, photoPath, java.lang.System.currentTimeMillis()+ ".jpg", "");
} catch (FileNotFoundException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
}
break;
}
目前代码是这样的,听说要刷新什么的,但是不知道该怎样写。求解决