安卓app调用系统照相功能拍出的图片在相册里面看不到,但在文件中看得到

vs_shell 2014-08-13 02:38:38
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;
}

目前代码是这样的,听说要刷新什么的,但是不知道该怎样写。求解决
...全文
536 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
vs_shell 2014-08-13
  • 打赏
  • 举报
回复
大神进来指点下吧

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧