if(cameraCode==requestCode){ Bundle bundle = data.getExtras(); photo= (Bitmap) bundle.get("data");// 获取相机返回的数据,并转换为Bitmap图片格式 ByteArrayOutputStream baos = new ByteArrayOutputStream(); photo.compress(Bitmap.CompressFormat.JPEG, 100, baos);// 把数据写入文件 Uri uri = data.getData(); Log.i(TAG, "uri = "+ uri); try { String[] pojo = {MediaStore.Images.Media.DATA}; Cursor cursor = managedQuery(uri, pojo, null, null,null); if(cursor!=null){ int colunm_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); String path = cursor.getString(colunm_index); if(path!=null){ picPath=path; imageView.setImageBitmap(photo); } } }catch (Exception e) { // TODO: handle exception } }
此返回值跟上面本地取图片一样。返回picPath,并且将图片填充至imageView。
上传: