2012-02-21 65 views
1

我使用JSON解析在我的網址非常大尺寸圖像在那裏,我希望讓那些無法下載圖像.....任何機構可以幫助我獲得這些圖像 我的代碼如下enter code here如何解析非常大的圖像?

公共類Image延伸活動{

String imageBaseDirectory = "http://www.dha.com.tr/newpics/news/"; 

Bitmap bit; 

public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.image); 

    ImageView img=(ImageView)findViewById(R.id.ImageView01); 


    img.setImageBitmap(convertImage(imageBaseDirectory)); 


} 

公共位圖convertImage(字符串或多個) {

 URL aURL = null; 
     try 
     { 
     final String imageUrl =s.replaceAll(" ","%20"); 
     Log.e("Image Url",imageUrl); 
     aURL = new URL(imageUrl); 
     URLConnection conn = aURL.openConnection(); 
     InputStream is = conn.getInputStream(); 
     //@SuppressWarnings("unused") 
     BufferedInputStream bis = new BufferedInputStream(is); 
     Bitmap bm = BitmapFactory.decodeStream(new PatchInputStream(bis)); 
     if(bm==null){} 
     else 
      bit=Bitmap.createScaledBitmap(bm,60, 60, true); 

     return bit; 

     } 
     catch(Exception e) 
     { 
      e.printStackTrace(); 
       return null; 
     } 
} 
+0

重複http://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue – 2012-02-21 13:35:50

回答

0
Try this code I hope it will help. 

private Bitmap LoadPhotoFromServer(String path){ 

     Bitmap bm=null; 

     URL url = null; 
     try { 
      url = new URL(path); 
     } catch (MalformedURLException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } 


     try{ 


      HttpURLConnection httpConnection=(HttpURLConnection)url.openConnection(); 
      httpConnection.setDoInput(true); 
      httpConnection.connect(); 
      //int lengthOfFile=httpConnection.getContentLength(); 
      InputStream inputStream=httpConnection.getInputStream(); 
      bm=BitmapFactory.decodeStream(inputStream); 
     } 

     catch (MalformedURLException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 


     return bm; 


    } 
+0

這也是行不通的...圖片沒有下載請用另一種方式幫助 – Santosh 2012-02-22 05:12:09