【发布时间】:2018-07-12 07:08:02
【问题描述】:
我正在从图库中加载图片并将其设置为 imageview,但我有一个旋转图像的功能,该功能需要图像 Uri。当我从内存中读取图片时,我使用以下代码
if(ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, EXTERNAL_STORAGE_PERMISSION);
}else{
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_FILE);
}
然后
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == SELECT_FILE){
if(resultCode == RESULT_OK){
imageUri = data.getData();
InputStream imageStream = null;
try {
imageStream = getContentResolver().openInputStream(imageUri);
}catch (IOException e){e.printStackTrace();}
final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
final Bitmap rotatedImage = rotateBitmap(selectedImage, **image file path**);
profilePic.setImageBitmap(rotatedImage);
}
}
}
函数rotateBitmap()需要图片的文件路径,不知道怎么获取...
【问题讨论】:
-
没有“文件路径”。您的
rotateBitmap()方法需要重写,或者您需要提供自己的写入路径。
标签: android image file-io inputstream