下面列出了android.graphics.drawable.Drawable#createFromResourceStream() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static Drawable extractDrawable(Context context, String fileName) throws Exception {
InputStream inputStream = context.getAssets().open(fileName);
DisplayMetrics dm = context.getResources().getDisplayMetrics();
TypedValue value = new TypedValue();
value.density = dm.densityDpi;
Drawable drawable = Drawable.createFromResourceStream(context.getResources(), value, inputStream, fileName);
inputStream.close();
return drawable;
}
private static Drawable extractDrawable(Context context, String s)
{
InputStream inputstream = context.getAssets().open(s);
DisplayMetrics displaymetrics = context.getResources().getDisplayMetrics();
TypedValue typedvalue = new TypedValue();
typedvalue.density = displaymetrics.densityDpi;
Drawable drawable = Drawable.createFromResourceStream(context.getResources(), typedvalue, inputstream, s);
inputstream.close();
return drawable;
}
/**
* Get the Drawable from URL
*
* @param urlString
* @return
*/
public Drawable fetchDrawable(String urlString) {
try {
InputStream is = fetch(urlString);
Drawable drawable = Drawable.createFromResourceStream(App.getContext().getResources(), null, is, "src");
L.d("%d----------X------ %d--%s", drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), urlString);
drawable.setBounds(0, 0, 0 + drawable.getIntrinsicWidth(), 0 + drawable.getIntrinsicHeight());
return drawable;
} catch (Exception e) {
return null;
}
}
/**
* Create a drawable from an inputstream, using the given resources and value to determine
* density information.
*/
public static Drawable createFromResourceStream(Resources res, TypedValue value, InputStream is, String srcName, BitmapFactory.Options opts) {
return Drawable.createFromResourceStream(res, value, is, srcName, opts);
}
/**
* Create a drawable from an inputstream, using the given resources and
* value to determine density information.
*/
public static Drawable createFromResourceStream(Resources res, TypedValue value, InputStream is, String srcName, BitmapFactory.Options opts) {
return Drawable.createFromResourceStream(res, value, is, srcName, opts);
}