我有一种方法,可以从数据库中查询一个网址,并在打开活动以进行缩放,平移等之前作为额外的发送。
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);
}
}
}
});
});
活动开始时,出现以下异常:
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提供一个网址吗?我想我也不能使用毕加索?我该怎么办呢?
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);
}
最佳答案
我想我不能只为SubsamplingScaleImageView提供一个网址吗?
如果这是您的意思,则它无法处理http
/ https
URL。
我想我也不能使用毕加索?
并不是的。它的作用是加载完整的位图,这不是您想要的。
我该怎么办呢?
您可以使用自己喜欢的HTTP客户端API(HttpUrlConnection
,OkHttp等)自己下载图像到文件。然后,将文件加载到SubsamplingScaleImageView
中。