1.String转uri,uri转drawble:
Uri uri=Uri.parse(”“);
Drawable d=Drawable.createFromStream(getContext().getContentResolver().openInputStream(uri),"");
2.int转bitmap,bitmap,转drawble:
//int转bitmap:
@SuppressLint("ResourceType") InputStream is = getResources().openRawResource(R.drawable.joey);
//bitmap转drawble:
Drawable drawable = BitmapDrawable.createFromStream(is, null);
3.String转bitmap:
//图片转换的方法:
public Bitmap returnBitMap(final String url){
new Thread(new Runnable() {
@Override
public void run() {
URL imageurl = null;
try {
imageurl = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection conn = (HttpURLConnection)imageurl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
return bitmap;
}