views:

64

answers:

1

please help me,

how to get bitmap object from an Uri (i suppose i succeed to store it in /data/data/MYFOLDER/myimage.png or file///data/data/MYFOLDER/myimage.png i used both path) to use it in my application

but i failed to get it, Someone have an idea how to accomplish this

thanx,

A: 

You could try this:

public Bitmap loadBitmap(String url)
{
    Bitmap bm = null;
    InputStream is = null;
    BufferedInputStream bis = null;
    try 
    {
        URLConnection conn = new URL(url).openConnection();
        conn.connect();
        is = conn.getInputStream();
        bis = new BufferedInputStream(is, 8192);
        bm = BitmapFactory.decodeStream(bis);
    }
    catch (Exception e) 
    {
        e.printStackTrace();
    }
    finally {
        if (bis != null) 
        {
            try 
            {
                bis.close();
            }
            catch (IOException e) 
            {
                e.printStackTrace();
            }
        }
        if (is != null) 
        {
            try 
            {
                is.close();
            }
            catch (IOException e) 
            {
                e.printStackTrace();
            }
        }
    }
    return bm;
}

But remember, this method should only be called from within a thread (not GUI -thread). I a AsyncTask.

PHP_Jedi
thanx but am talking a about an URI not an URL
ilredelweb
What about converting the URI to an url, e.g by using yourUri.toURL() ?
PHP_Jedi