1

i am using json parsing in my url a very big size images are there and i want get those images but not downloaded .....can any body help me to get those images my code is as followsenter 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;
        }
 }
Santosh
  • 611
  • 2
  • 6
  • 24

1 Answers1

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;


    }
Sam
  • 322
  • 1
  • 6