本文介绍了毕加索库不从的Adroid SD卡载入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从图片库路径的文件,并尝试按以下步骤加载一个图像视图。文件路径是:/storage/sdcard0/DCIM/Camera/1436267579864.jpg。我也试过路过乌里我也看过权限到SD卡上。

它结束了在的onError()方法。然而类似的方法工作正常的网页的URL。我该如何解决此问题?

 私人无效的getImage(档案文件){

        如果(file.exists()){

            Picasso.with(活动)
                    .load(文件)
                    .error(R.drawable.noimage)
                    。走进(IMG preVIEW,新的回调(){
                        @覆盖
                        公共无效的onSuccess(){
                            如果(进度= NULL和放大器;!&安培;!IMG preVIEW = NULL){

                                IMG preview.setVisibility(View.VISIBLE);
                                IMG preview.setTag(装);
                                progressBar.setVisibility(View.GONE);

                            }
                        }

                        @覆盖
                        公共无效onerror的(){
                            如果(进度= NULL和放大器;!&安培;!IMG preVIEW = NULL){
                                IMG preview.setVisibility(View.VISIBLE);
                                progressBar.setVisibility(View.GONE);
                            }
                        }

                    });
   }
 


    

 <使用-权限的Andr​​oid:名称=android.permission.WRITE_EXTERNAL_STORAG​​E/>
<使用-权限的Andr​​oid:名称=android.permission.READ_EXTERNAL_STORAG​​E/>
<使用-权限的Andr​​oid:名称=android.permission.INTERNET对/>
<使用-权限的Andr​​oid:名称=android.permission.ACCESS_NETWORK_STATE/>
 

解决方案

虽然为时已晚,但我还是坚持到同样的问题,所以我解决了下面的方法。仅仅使用和追加的文件://在路径的开始。看看这样的:

  Picasso.with(上下文)//
                    .load(文件://+ myFilePath)//
                    .error(R.mipmap.error)
                    .placeholder(R.mipmap.ic_launcher)
                    。适合()
                    .TAG(MyActivity.this)//
                    。走进(ImageView的,新的ImageLoadedCallback(进度){
                        @覆盖
                        公共无效的onSuccess(){
                            progressBar.setVisibility(View.GONE);
                        }

                        @覆盖
                        公共无效onerror的(){
                            Log.d(毕加索错误,错误);

                        }
                    });
 

这解决了我的问题。只是回答,这样如果有一个人摔倒在同样的问题,来这里的解决方案,那么他可能会得到他的问题,通过这个解决。

I take a file from path from image gallery and try to load it a image view as follows. File path is: /storage/sdcard0/DCIM/Camera/1436267579864.jpg. I also tried passing Uri I also have read privileges to SD card.

It ends up in onError() method. However similar method works fine for web urls. How can I resolve this?

private void getImage(File file) {

        if(file.exists()) {

            Picasso.with(activity)
                    .load(file)
                    .error(R.drawable.noimage)
                    .into(imgPreview, new Callback() {
                        @Override
                        public void onSuccess() {
                            if (progressBar != null && imgPreview != null) {

                                imgPreview.setVisibility(View.VISIBLE);
                                imgPreview.setTag("loaded");
                                progressBar.setVisibility(View.GONE);

                            }
                        }

                        @Override
                        public void onError() {
                            if (progressBar != null && imgPreview != null) {
                                imgPreview.setVisibility(View.VISIBLE);
                                progressBar.setVisibility(View.GONE);
                            }
                        }

                    });
   }


<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
解决方案

Though it is too late , but I stuck into same problem, so I solved in the following way . Just using and appending "file://" in the starting of path. take a look at this:

 Picasso.with(context) //
                    .load("file://" +myFilePath) //
                    .error(R.mipmap.error)
                    .placeholder(R.mipmap.ic_launcher)
                    .fit()
                    .tag(MyActivity.this) //
                    .into(imageView, new ImageLoadedCallback(progressBar) {
                        @Override
                        public void onSuccess() {
                            progressBar.setVisibility(View.GONE);
                        }

                        @Override
                        public void onError() {
                            Log.d("Picasso Error", "Error");

                        }
                    });

This solves my problem . Just answering so that if some one fall in the same problem and came here for solution then he may get his problem solved through this.

这篇关于毕加索库不从的Adroid SD卡载入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 21:05