0

웹 서버에서 이미지를 다운로드하는 여러 가지 방법을 사용하여 이미지보기로 표시했습니다. 다운로드 후 이미지 뷰에서 이미지가 공백으로 표시되는 것과 같은 문제에 직면하고 있습니다. 나는 내가 어디가 잘못되었는지 알지 못한다. 에뮬레이터를 사용하고 있습니다.다운로드 된 이미지가 이미지보기에 공백으로 표시됩니다.

이이

ImageView v_thumburl = (ImageView) rowView 
       .findViewById(R.id.v_thumb_url); 
     thumburl = temp.getString(temp.getColumnIndex("thumburl")); 
     Drawable drawable = LoadImageFromWebOperations(thumburl); 
     v_thumburl.setImageDrawable(drawable); 

private Drawable LoadImageFromWebOperations(String url) { 
    try { 
     InputStream is = (InputStream) new URL(url).getContent(); 
     Drawable d = Drawable.createFromStream(is, "src name"); 
     return d; 
    } catch (Exception e) { 
     System.out.println("Exc=" + e); 
     return null; 
    } 
} 

이 시도 내가 loding img와 양식의 URL이 코드를 사용하여 이미지

private class LongOperation extends AsyncTask<String, Void, String> { 



     @Override 

     protected String doInBackground(String... params) { 

     // perform long running operation operation 

       Bitmap message_bitmap = null; 
       // Should we download the image? 
       if ((image_url != null) && (!image_url.equals("")))    
          { 
        message_bitmap = 
         ImageDownloader.DownloadImage(image_url); 

       } 
       // If we didn't get the image, we're out of here 
       if (message_bitmap == null) { 

        Log.d("Image", "Null hai"); 
       } 

     return null; 

     } 





     @Override 

     protected void onPostExecute(String result) { 

     // execution of result of Long time consuming operation 
      pDialog.dismiss(); 
      iv.setImageDrawable(message_bitmap); 
      Log.d("Image", "Displayed"); 
     } 



     /* (non-Javadoc) 
       * @see android.os.AsyncTask#onPreExecute() 

     */ 

     @Override 

     protected void onPreExecute() { 

     // Things to be done before execution of long running operation. 
      pDialog = new ProgressDialog(CommonUtilities.this); 
      pDialog.setMessage(Html.fromHtml("Please Wait...")); 
      pDialog.setIndeterminate(false); 
      pDialog.setCancelable(false); 
      pDialog.show(); 
     } 







    } 

답변

0

를 표시하는 내 코드 다운로드 이미지

private static InputStream OpenHttpConnection(String urlString) 
     throws IOException 
     { 
      InputStream in = null; 
      int response = -1; 

      URL url = new URL(urlString); 
      URLConnection conn = url.openConnection(); 

      if (!(conn instanceof HttpURLConnection))      
       throw new IOException("Not an HTTP connection"); 

      try{ 
       HttpURLConnection httpConn = (HttpURLConnection) conn; 
       httpConn.setAllowUserInteraction(false); 
       httpConn.setInstanceFollowRedirects(true); 
       httpConn.setRequestMethod("GET"); 
       httpConn.connect(); 

       response = httpConn.getResponseCode();     
       if (response == HttpURLConnection.HTTP_OK) { 
        in = httpConn.getInputStream();         
       }      
      } 
      catch (Exception ex) 
      { 
       throw new IOException("Error connecting");    
      } 
      return in;  
     } 
     static Bitmap DownloadImage(String URL) 
     {   
      Bitmap bitmap = null; 
      InputStream in = null;   
      try { 
       in = OpenHttpConnection(URL); 
       bitmap = BitmapFactory.decodeStream(in); 
       in.close(); 
      } catch (IOException e1) { 
       // TODO Auto-generated catch block 
       e1.printStackTrace(); 
      } 
      return bitmap;     
     } 

내 코드입니다 도움이되기를 바랍니다.

+0

이미지를 다운로드하고 SD 카드에 저장하고 싶습니다. – user1918034

+0

로그에 오류가 있습니다. – Jagan

+0

jpeg 디코더를 보여줍니다. 결과 : 0 – user1918034

0
웹 서버 이미지

사용 게으른 로딩 및 이미지 뷰에서 설정 ...이에서 Example 나는이 문제가 현재뿐만 아니라 미래에도 도움이되기를 바랍니다. :-)

관련 문제