2016-07-26 139 views
0

库存,因为后端开发人员在FTP服务器中存储图像,我需要在ImageView中显示这些图像而不保存到SD卡。Android - FTP在ImageView中显示图像,但不存储图像中的图像

是否有可能检索图像(jpg/png)并将其转换为位图并直接将其显示到ImageView而无需保存。

我在寻找很多,但所有使用的工艺都保存到SD卡的方式。

+0

如果你有直接的URL的文件,然后你可以从URI –

+0

图像加载到ImageView的是,我有直接的URL的形象,请我需要更多的帮助,在打击代码没有工作与我..图像仍然没有出现。 – Safa

+0

添加断点并记录变量的值。下面的代码应该可以工作,它为我工作。 **除非你有FTP所需的一些认证** –

回答

0
public class async extends AsyncTask<String, Integer, Bitmap> { 

    @Override 
    protected Bitmap doInBackground(String... strings) { 
     public static Bitmap getBitmapFromURL(String src) { 
      try { 
       URL url = new URL(src); 
       HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
       connection.setDoInput(true); 
       connection.connect(); 
       InputStream input = connection.getInputStream(); 
       Bitmap myBitmap = BitmapFactory.decodeStream(input); 
       return myBitmap; 
      } catch (IOException e) { 
       // Log exception 
       return null; 
      } 
     } 
    } 

    @Override 
    protected void onPostExecute(Bitmap result) { 
     if(result != null) 
      imageView.setImageBitmap(result) 
    } 
}