Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.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 我能';我找不到毕加索在sd卡上保存图像的地方_Android_Path_Sd Card_Picasso - Fatal编程技术网

Android 我能';我找不到毕加索在sd卡上保存图像的地方

Android 我能';我找不到毕加索在sd卡上保存图像的地方,android,path,sd-card,picasso,Android,Path,Sd Card,Picasso,我使用毕加索下载图像并在我的安卓应用程序中显示,它工作正常。现在我想下载第一页中的所有图像,并在第二页中显示它们。问题是,图像将保存在哪里?我需要路径在那里下载图像。 有没有办法访问路径或更改路径?您可以使用其URRL将图像下载到内部存储器上的所需路径,然后使用以下两种方法将其加载到图像视图中: public void downloadImagesToSdCard(String downloadUrl, String imageName) //downloadURL is the url of

我使用毕加索下载图像并在我的安卓应用程序中显示,它工作正常。现在我想下载第一页中的所有图像,并在第二页中显示它们。问题是,图像将保存在哪里?我需要路径在那里下载图像。
有没有办法访问路径或更改路径?

您可以使用其URRL将图像下载到内部存储器上的所需路径,然后使用以下两种方法将其加载到图像视图中:

public void downloadImagesToSdCard(String downloadUrl, String imageName)
 //downloadURL is the url of your image and imageName is the name you choose for your image file on internal storage

{
    try
    {
        URL url = new URL(downloadUrl);
                    /* making a directory in sdcard */
        String sdCard= Environment.getExternalStorageDirectory().toString();
        File myDir = new File(sdCard,"Your Arbitrary Folder Name");

                    /*  if specified not exist create new */
        if(!myDir.exists())
        {
            myDir.mkdir();
            Log.v("", "inside mkdir");
        }

                    /* checks the file and if it already exist delete */
        String fname = imageName;
        File file = new File (myDir, fname);
        if (file.exists ())
            file.delete ();

                         /* Open a connection */
        URLConnection ucon = url.openConnection();
        InputStream inputStream = null;
        HttpURLConnection httpConn = (HttpURLConnection)ucon;
        httpConn.setRequestMethod("GET");
        httpConn.connect();

        if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK)
        {
            inputStream = httpConn.getInputStream();
        }

        FileOutputStream fos = new FileOutputStream(file);
        int totalSize = httpConn.getContentLength();
        int downloadedSize = 0;
        byte[] buffer = new byte[2048];
        int bufferLength = 0;
        while ( (bufferLength = inputStream.read(buffer)) > 0 )
        {
            fos.write(buffer, 0, bufferLength);
            downloadedSize += bufferLength;
            Log.i("Progress:","downloadedSize:"+downloadedSize+"totalSize:"+ totalSize) ;
        }

        fos.close();
        Log.d("test", "Image Saved in sdcard..");
    }
    catch(IOException io)
    {
        io.printStackTrace();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}`
使用上述方法后,您的图像将从输入url下载到设备内部存储器中指定的文件夹和图像名称(imageName)。然后您应该将图像从该路径加载到ImageView。您可以使用以下方法执行此操作:

public Bitmap loadToImageView(ImageView myImage, String sd_address) {
        Bitmap myBitmap = null;
        //File imgFile = new  File("/sdcard/Your Arbitary Folder  Name/matin.jpg");
        File imgFile = new File(sd_address);
        if (imgFile.exists()) {
            myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

            //ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);

            myImage.setImageBitmap(myBitmap);

        }
        return myBitmap;
    }

因此,使用setImageBitmap方法将图像从指定的sd_地址加载到imageview。我希望这对你有帮助!:)

我相信毕加索会在环境中缓存图像。getCache()dir如果你在模拟器上运行应用程序,并使用ddms浏览应用程序的data.data文件夹,你应该看到图像的缓存位置。难道不可能在第二页再次使用具有相同URL的毕加索吗?毕加索不会再下载它们,而是从缓存中获取它们。这就是我的想法。毕加索使用LruCache实例作为缓存,因此图像没有路径——图像保存在内存中