2017-12-26 4 views
-1

글라이드를 사용하여 장치를 다운로드 한 후 장치에 이미지를 저장하는 방법.장치에 이미지를 저장하는 방법

Glide.with(Main2Activity.this) 
      .load(string) 
      .into(imageView); 
+0

글라이드는 이미 당신이 필요하지 않은 이미지를 다운로드하는 위의 마시멜로를 위해 WRITE_EXTERNAL_STORAGE 권한을 요청 받기 장치에 이미지를 저장하면 이미지를 다운로드 할 수 있습니다. 이미지를 다운로드하려면 비동기 작업을 완료해야합니다. –

답변

0

당신은

Glide.with(this) 
      .load(string) 
      .into(imageView); 

이미지가 자동으로 캐시 일들이 앱에서 변경되지 않는 경우는 전화의 캐시에서 동일한 캐시 이미지를로드합니다 그래서 작업을 수행 할 때.

당신이

https://stackoverflow.com/a/15549639/6683139

+0

이 이미지를 어떻게 다운로드 할 수 있습니까? –

+0

내 대답을 다시 확인하고 링크 –

+0

을 따라 주셔서 감사합니다. –

0

이 대답

public void downloadFile(String url) { 
    File direct = new File(Environment.getExternalStorageDirectory() 
      + "/AnhsirkDasarp"); 

    if (!direct.exists()) { 
     direct.mkdirs(); 
    } 

    DownloadManager mgr = (DownloadManager) getApplicationContext().getSystemService(Context.DOWNLOAD_SERVICE); 

    Uri downloadUri = Uri.parse(url); 
    DownloadManager.Request request = new DownloadManager.Request(
      downloadUri); 

    request.setAllowedNetworkTypes(
      DownloadManager.Request.NETWORK_WIFI 
        | DownloadManager.Request.NETWORK_MOBILE) 
      .setAllowedOverRoaming(false).setTitle("Demo") 
      .setDescription("Something useful. No, really.") 
      .setDestinationInExternalPublicDir("/AnhsirkDasarpFiles", "fileName.jpg"); 

    mgr.enqueue(request); 

} 

에게 비록 완전히 다른 일이있어 그 갤러리에 다운로드하려면 ............. .................................................. .................................................. .................................................. .................................................. .............................................

,
0

이 시도 : 사용 위의

Glide 4.0이 코드 :

Glide.with(this) 
      .asBitmap() 
      .load(path) 
      .into(new SimpleTarget<Bitmap>() { 
       @Override 
       public void onResourceReady(Bitmap bitmap, Transition<? super Bitmap> transition) { 
        imageView.setImageBitmap(bitmap); 

        //Bitmap storing to external storage 
        try { 
         if (bitmap != null) { 
          File newfile = new File(Environment.getExternalStorageDirectory() + "/directoryname"); 
          if (!newfile.isDirectory()) { 
           newfile.mkdir(); 
          } 
          newfile = new File(Environment.getExternalStorageDirectory() + "/directoryname", "_" + System.currentTimeMillis() + ".jpg"); 
          try { 
           FileOutputStream fileOutputStream = new FileOutputStream(newfile); 
           if (bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream)) { 
            //Image saved 
           } else { 
            //Image saving unsuccessfull 
           } 
          } catch (IOException e) { 
           e.printStackTrace(); 
          } finally { 
           try { 
            if (fileOutputStream != null) { 
             fileOutputStream.close(); 
            } 
           } catch (IOException e) { 
            e.printStackTrace(); 
           } 
          } 

         } 
        } catch (Exception e) { 
         e.printStackTrace(); 
        } 
       } 
      }); 

을 수동으로

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
관련 문제