无法将URL设置为SubsamplingScaleImageView URI

时间:2016-10-01 18:47:33

标签: java android url uri subsampling

我有一种方法,从我的数据库中查询Url并在打开活动之前作为额外信息发送,您可以在其中进行缩放,平移等。

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)

活动开始时,我会收到以下例外

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)));*/
    }
}

我想我不能只为SubamplingScaleImageView提供一个Url嗯?我想我也不能使用毕加索?我该怎么做呢?

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);
                }

我试过这个并且有效......

DateFormat timeFormat = DateFormat.getDateFormat(
            MyApplication.getInstance().getApplicationContext());

    if (timeFormat instanceof SimpleDateFormat) {
        String pattern = ((SimpleDateFormat) timeFormat).toPattern()
        // Change year format on 2 digits
        pattern = pattern.replaceAll("yyyy", "yy");            
        timeFormat = new SimpleDateFormat(pattern);
    }      

    return timeFormat.format(dateTime.toDate());

1 个答案:

答案 0 :(得分:1)

  

我想我不能只为SubamplingScaleImageView提供一个Url嗯?

如果您的意思是这样,则无法处理http / https个网址。

  

我想我也不能使用毕加索?

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

  

我该怎么办?

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