Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从android中url的arraylist获取图像文件对象的arraylist_Android_Arraylist_Android Bitmap_Android File - Fatal编程技术网

从android中url的arraylist获取图像文件对象的arraylist

从android中url的arraylist获取图像文件对象的arraylist,android,arraylist,android-bitmap,android-file,Android,Arraylist,Android Bitmap,Android File,我的目标是: 需要从url字符串中的api调用获取图像路径,如: 需要将图像路径发送到文件对象中的api调用。 所以我只选ArrayList。 当图像转换为文件对象时,我应该在imageview中显示图像路径 我正在尝试使用以下不同文件对象的解决方案: File f=null; URL url = new URL(info4Model.getExternal_photos().get(position).getImage_path()); try { /

我的目标是:

需要从url字符串中的api调用获取图像路径,如: 需要将图像路径发送到文件对象中的api调用。 所以我只选ArrayList。 当图像转换为文件对象时,我应该在imageview中显示图像路径

我正在尝试使用以下不同文件对象的解决方案:

File f=null;
    URL url = new URL(info4Model.getExternal_photos().get(position).getImage_path());
        try {
         //   f = new File(url.toURI());//java.lang.IllegalArgumentException: Expected file scheme in URI:
            //f = new File(url.getPath());//  not showing file object in imageview
            //f = new File(url.getFile());// not showing file object in imageview
            f = getFileFromBitmap(info4Model.getExternal_photos().get(position).getImage_path());
             //android.os.NetworkOnMainThreadException , AsyncTask option left only?

        } catch (Exception e) {


        }
///////////////////////////////////
public static Bitmap getBitmapFromURL(String url) {
    try {
        URL url1 = new URL(url);
        HttpURLConnection connection = (HttpURLConnection) url1.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();
        Bitmap bitmapFrmUrl = BitmapFactory.decodeStream(input);
        return bitmapFrmUrl;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }catch (Exception e){
        e.printStackTrace();
        return null;
    }
}
File getFileFromBitmap(String url) {
    Bitmap bmp = getBitmapFromURL(url);

    SimpleDateFormat simpleDateFormat =
            new SimpleDateFormat("MMddhhmmss");
    String dateAsString = simpleDateFormat.format(new Date());
    File filesDir = getActivity().getFilesDir();
    File imageFile = new File(filesDir, dateAsString + ".png");

    OutputStream os;
    try {
        os = new FileOutputStream(imageFile);
        bmp.compress(Bitmap.CompressFormat.PNG, 100, os);
        os.flush();
        os.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return imageFile;
}
在这里,所有文件对象都在语句后的注释中显示失败结果

public class FileModel {
    File Url;
    File path;
    File file;
    File bitMap;

    public File getUrl() {
        return Url;
    }

    public void setUrl(File url) {
        Url = url;
    }

    public File getPath() {
        return path;
    }

    public void setPath(File path) {
        this.path = path;
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public File getBitMap() {
        return bitMap;
    }

    public void setBitMap(File bitMap) {
        this.bitMap = bitMap;
    }
    }  

  ArrayList<FileModel> fileArrayList = new ArrayList<>();

FileModel fileModel = new FileModel();
        File f=null;
        URL url = new URL(info4Model.getExternal_photos().get(position).getImage_path());
        try {
            f = new File(url.toURI());//java.lang.IllegalArgumentException: Expected file scheme in URI:
            fileModel.setUrl(f);
            f = new File(url.getPath());//  not showing file object in imageview
            fileModel.setPath(f);
            f = new File(url.getFile());// not showing file object in imageview
            fileModel.setFile(f);
            f = getFileFromBitmap(info4Model.getExternal_photos().get(position).getImage_path());
            fileModel.setBitMap(f);
            //android.os.NetworkOnMainThreadException , AsyncTask option left only?

        } catch (Exception e) {

            e.printStackTrace();
        }

        fileArrayList.add(fileModel);
最后,可以使用文件arraylist了


我希望这对你有帮助

如果从api获取图像url

那么, 阿联酋毕加索将您的图像加载到imageview中,如。。 毕加索。WithActivityName.this

。请在此处加载您的图像URL

.intoimageView

用于api加载图像路径。。 您必须使用多部分

为此

文件=新文件的图像路径; FileBody a1=新的FileBody文件

多方实体MPENTY=新多方实体;mpEntity.addPartparam名称,a1


希望您能得到帮助。

谢谢,但是您可以看到,所有对象都对结果进行了注释。所以我的问题是,从所有这些文件中,没有一个单一的文件对象在工作。你需要包装一个单一的模型类,然后将所有的值放在模型中,并将模型放在ArrayList中。。。!