gpt4 book ai didi

java - 无法将 URL 设置为 SubsamplingScaleImageView URI

转载 作者:行者123 更新时间:2023-12-01 09:26:17 24 4
gpt4 key购买 nike

我有一种方法,在打开可以缩放、平移等的 Activity 之前,从我的数据库中查询 Url 并作为额外内容发送。

topLevelMessageImage.setOnClickListener(v -> {

ParseQuery<ParseObject> imageQuery = new ParseQuery<>(ParseConstants.CLASS_YEET);
imageQuery.whereEqualTo(ParseConstants.KEY_OBJECT_ID, topLevelCommentObject.getObjectId());
imageQuery.findInBackground((user, e2) -> {
if (e2 == null) for (ParseObject userObject : user) {

if (userObject.getParseFile("image") != null) {
String imageURL = userObject.getParseFile("image").getUrl();
Log.w(getClass().toString(), imageURL);

// Asynchronously display the message image downloaded from Parse
if (imageURL != null) {

Intent intent = new Intent(getApplicationContext(), MediaPreviewActivity.class);
intent.putExtra("imageUrl", imageURL);
this.startActivity(intent);

}

}
}
});
});

当 Activity 开始时,我收到以下异常:

10-01 20:46:08.202 16149-16460/com.yitter.android E/SubsamplingScaleImageView: Failed to initialise bitmap decoder


java.io.FileNotFoundException: No content provider: https://parsefiles.back4app.com/GDprTC66bNMp3mXWNvWJbZhWwjedoucvp6NlNKVl/03a8e1618392395811c9830333c0443f_6cf1e0ef-47af-4ddc-88cc-196debd77a9a.jpeg
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1090)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:942)
at android.content.ContentResolver.openInputStream(ContentResolver.java:662)
at com.davemorrissey.labs.subscaleview.decoder.SkiaImageRegionDecoder.init(SkiaImageRegionDecoder.java:67)
at com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView$TilesInitTask.doInBackground(SubsamplingScaleImageView.java:1415)
at com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView$TilesInitTask.doInBackground(SubsamplingScaleImageView.java:1391)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)

我想我不能只向 SubsamplingScaleImageView 提供一个 Url 是吗?我想我也不能使用毕加索?我该怎么办?

private void locateImageView() {

Bundle bundle = getIntent().getExtras();
if (bundle != null) {
if (bundle.getString("imageUrl") != null) {
String imageUrl = bundle.getString("imageUrl");
Log.w(getClass().toString(), imageUrl);

imageView = (SubsamplingScaleImageView) findViewById(R.id.image);

URL url = new URL(imageUrl);
URI uri = url.toURI();

imageView.setImage(ImageSource.uri(String.valueOf(uri)));

/*Picasso.with(getApplicationContext())
.load(imageUrl)
.placeholder(R.color.placeholderblue)
.memoryPolicy(MemoryPolicy.NO_CACHE).into(((SubsamplingScaleImageView) findViewById(R.id.image)));*/
}
}

我尝试了这个,它成功了......

try {
URL url = new URL(imageUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);

imageView.setImage(ImageSource.bitmap(myBitmap);

} catch (IOException e) {
// Log exception
Log.w(getClass().toString(), e);
}

最佳答案

I suppose I can't just feed the SubsamplingScaleImageView a Url eh?

它无法处理 http/https URL,如果这就是您的意思。

I guess I can't use Picasso either?

不是真的。它的作用是加载完整的位图,这不是你想要的。

What should I do instead?

使用您最喜欢的 HTTP 客户端 API(HttpUrlConnection、OkHttp 等)自行将图像下载到文件中。然后,将文件加载到 SubsamplingScaleImageView 中。

关于java - 无法将 URL 设置为 SubsamplingScaleImageView URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39810287/

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