作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试将图库中的图像显示到 SimpleDraweeView 中。我不知道这是不是这样做的方法,但我正在做的是进入画廊,选择图像并获取图像路径。之后,我使用 galleryImage.setImageURI(Uri.parse(url));
将图像设置到 SimpleDraweeView(这是 galleryImage 的类型)中。不幸的是,我发现 Bitmap 太大而无法上传到纹理中 (4128x2322, max=4096x4096)
。
这是我打开图库并返回 imagePath 的代码。
public void loadImagefromGallery(View view) {
// Create intent to Open Image applications like Gallery, Google Photos
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Start the Intent
startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
}
// When Image is selected from Gallery
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
// When an Image is picked
if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK
&& null != data) {
// Get the Image from data
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
// Get the cursor
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
// Move to first row
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imgPath = cursor.getString(columnIndex);
cursor.close();
Toast.makeText(this, imgPath,
Toast.LENGTH_LONG).show();
String url = "file://" + imgPath;
galleryImage.setImageURI(Uri.parse(url));
} else {
Toast.makeText(this, "You haven't picked Image",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG)
.show();
}
}
编辑:
ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
.setAutoRotateEnabled(true)
.setResizeOptions(new ResizeOptions(galleryImage.getLayoutParams().width, galleryImage.getLayoutParams().height));
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setImageRequest(imageRequestBuilder.build())
.setOldController(galleryImage.getController())
.build();
galleryImage.setController(controller);
最佳答案
ImagePipelineConfig frescoConfig = ImagePipelineConfig.newBuilder(getApplicationContext()) .setDownsampleEnabled(true).build();
Fresco.initialize(this, frescoConfig);
它对我有用。
关于android - Fresco - 位图太大而无法上传到纹理中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33676807/
我是一名优秀的程序员,十分优秀!