如何解析非常大的图像?

时间:2012-02-21 13:32:45

标签: android

我在我的网址中使用json解析一个非常大的图像在那里我想要获得那些图像但是没有下载.....可以任何身体帮助我获取这些图像 我的代码如下enter code here

public class Image extends Activity {

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));


}

public Bitmap convertImage(String s)      {

        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;
        }
 }

1 个答案:

答案 0 :(得分: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;


    }