gpt4 book ai didi

android - Fresco - 位图太大而无法上传到纹理中

转载 作者:太空狗 更新时间:2023-10-29 16:33:37 28 4
gpt4 key购买 nike

我正在尝试将图库中的图像显示到 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com