本文整理了Java中android.graphics.drawable.Drawable.createFromStream()
方法的一些代码示例,展示了Drawable.createFromStream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Drawable.createFromStream()
方法的具体详情如下:
包路径:android.graphics.drawable.Drawable
类名称:Drawable
方法名:createFromStream
暂无
代码示例来源:origin: PrivacyApps/html-textview
@Override
public Drawable getDrawable(String source) {
try {
InputStream inputStream = context.getAssets().open(source);
Drawable d = Drawable.createFromStream(inputStream, null);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
} catch (IOException e) {
// prevent a crash if the resource still can't be found
Log.e(HtmlTextView.TAG, "source could not be found: " + source);
return null;
}
}
代码示例来源:origin: aa112901/remusic
private void setAlbumart() {
albumTitle.setText(playlistname);
albumArtSmall.setImageURI(Uri.parse(albumPath));
final Drawable drawable;
try {
drawable = Drawable.createFromStream(getContext().getContentResolver().openInputStream(Uri.parse(albumPath)), null);
new setBlurredAlbumArt().execute(ImageUtils.getBitmapFromDrawable(drawable));
} catch (Exception e) {
}
}
代码示例来源:origin: aa112901/remusic
private void setAlbumart() {
albumTitle.setText(playlistname);
albumArtSmall.setImageURI(Uri.parse(albumPath));
final Drawable drawable;
try {
drawable = Drawable.createFromStream(PlaylistDetailActivity.this.getContentResolver().openInputStream(Uri.parse(albumPath)), null);
new setBlurredAlbumArt().execute(ImageUtils.getBitmapFromDrawable(drawable));
} catch (Exception e) {
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldInheritSourceStringFromDrawableDotCreateFromStream() throws Exception {
InputStream emptyInputStream = new ByteArrayInputStream("".getBytes(UTF_8));
BitmapDrawable drawable = (BitmapDrawable) Drawable.createFromStream(emptyInputStream, "source string value");
assertThat(shadowOf(drawable).getSource()).isEqualTo("source string value");
}
代码示例来源:origin: mikepenz/MaterialDrawer
/**
* this only handles Drawables
*
* @param ctx
* @param iconColor
* @param tint
* @return
*/
public Drawable decideIcon(Context ctx, int iconColor, boolean tint, int paddingDp) {
Drawable icon = getIcon();
if (mIIcon != null) {
icon = new IconicsDrawable(ctx, mIIcon).color(iconColor).sizeDp(24).paddingDp(paddingDp);
} else if (getIconRes() != -1) {
icon = AppCompatResources.getDrawable(ctx, getIconRes());
} else if (getUri() != null) {
try {
InputStream inputStream = ctx.getContentResolver().openInputStream(getUri());
icon = Drawable.createFromStream(inputStream, getUri().toString());
} catch (FileNotFoundException e) {
//no need to handle this
}
}
//if we got an icon AND we have auto tinting enabled AND it is no IIcon, tint it ;)
if (icon != null && tint && mIIcon == null) {
icon = icon.mutate();
icon.setColorFilter(iconColor, PorterDuff.Mode.SRC_IN);
}
return icon;
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testCreateFromStream_shouldSetTheInputStreamOnTheReturnedDrawable() throws Exception {
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(new byte[0]);
Drawable drawable = Drawable.createFromStream(byteInputStream, "src name");
assertThat(shadowOf(drawable).getInputStream()).isEqualTo((InputStream) byteInputStream);
}
代码示例来源:origin: Neamar/KISS
@SuppressWarnings("deprecation")
@Override
public Drawable getDrawable(Context context) {
synchronized (this) {
if (isDrawableCached())
return icon;
if (contactPojo.icon != null) {
InputStream inputStream = null;
try {
inputStream = context.getContentResolver()
.openInputStream(contactPojo.icon);
return icon = Drawable.createFromStream(inputStream, null);
} catch (FileNotFoundException ignored) {
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException ignored) {
}
}
}
}
// Default icon
return icon = context.getResources()
.getDrawable(R.drawable.ic_contact);
}
}
代码示例来源:origin: xuhongv/SmartHome
/**
* Byte transfer to drawable
*
* @param byteArray
* @return
*/
public static Drawable byteToDrawable(byte[] byteArray) {
ByteArrayInputStream ins = null;
if (byteArray != null) {
ins = new ByteArrayInputStream(byteArray);
}
return Drawable.createFromStream(ins, null);
}
代码示例来源:origin: freedom10086/Ruisi
/**
* 获得板块图标
*/
public static Drawable getForumlogo(Context contex, int fid) {
try {
InputStream ims = contex.getAssets().open("forumlogo/common_" + fid + "_icon.gif");
return Drawable.createFromStream(ims, null);
} catch (IOException ex) {
return null;
}
}
代码示例来源:origin: qyxxjd/AndroidBasicProject
/**
* 描述:获取Asset中的图片资源.
*
* @param context the context
* @param fileName the file name
* @return Drawable 图片
*/
public static Drawable getDrawableFromAsset(Context context,String fileName){
Drawable drawable = null;
try {
AssetManager assetManager = context.getAssets();
InputStream is = assetManager.open(fileName);
drawable = Drawable.createFromStream(is, null);
} catch (Exception e) {
e.printStackTrace();
}
return drawable;
}
代码示例来源:origin: ckcz123/PKUHelper-Android
public void run() {
try {
Drawable drawable = Drawable.createFromStream(
WebConnection.connect("http://dean.pku.edu.cn/student/yanzheng.php?act=init"),
"dean");
handler.sendMessage(Message.obtain(handler, Constants.MESSAGE_DEAN_PICTURE_FINISHED, drawable));
} catch (Exception | Error e) {
handler.sendEmptyMessage(Constants.MESSAGE_DEAN_PICTURE_FAILED);
}
}
}).start();
代码示例来源:origin: qyxxjd/BaseProject
/**
* 描述:获取Asset中的图片资源.
*
* @param context the context
* @param fileName the file name
* @return Drawable 图片
*/
public static Drawable getDrawableFromAsset(@NonNull Context context, @NonNull String fileName) {
Drawable drawable = null;
try {
AssetManager assetManager = context.getAssets();
InputStream is = assetManager.open(fileName);
drawable = Drawable.createFromStream(is, null);
} catch (Exception e) {
e.printStackTrace();
}
return drawable;
}
代码示例来源:origin: CloudRail/cloudrail-si-android-sdk
@Override
public void run() {
try {
InputStream is = (InputStream) new URL(mUrl).getContent();
final Drawable d = Drawable.createFromStream(is, null);
((Activity) mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
imageView.setImageDrawable(d);
}
});
} catch (Exception e) {
}
}
}).start();
代码示例来源:origin: GuoFeilong/LifeHelper
public static Drawable loadImageFromUrl(String url) {
URL m;
InputStream i = null;
try {
m = new URL(url);
i = (InputStream) m.getContent();
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Drawable d = Drawable.createFromStream(i, "src");
return d;
}
代码示例来源:origin: marzika/Snapprefs
public static Drawable fetchDrawable(String urlString) {
if (drawableMap.containsKey(urlString)) {
return drawableMap.get(urlString);
}
try {
InputStream is = fetch(urlString);
Drawable drawable = Drawable.createFromStream(is, "src");
if (drawable != null)
drawableMap.put(urlString, drawable);
return drawable;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
代码示例来源:origin: it.tidalwave.bluebill/it-tidalwave-android-utilities
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
public static Drawable loadImage (final @Nonnull String url)
throws IOException
{
log.info("loadImage({})", url);
final @Cleanup InputStream is = new BufferedInputStream((InputStream)(new URL(url).getContent()));
return Drawable.createFromStream(is, "src");
// return BitmapFactory.decodeStream(is);
}
代码示例来源:origin: JustinRoom/JSCKit
private void loadPicture(File file) {
InputStream is = null;
try {
is = new FileInputStream(file);
Drawable drawable = Drawable.createFromStream(is, null);
advertisementView.getImageView().setImageDrawable(drawable);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (is != null)
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: ckcz123/PKUHelper-Android
@Override
public void run() {
try {
InputStream inputStream = WebConnection.connect(urls.get(j));
Drawable drawable = Drawable.createFromStream(inputStream, j + ".png");
eventHandler.sendMessage(Message.obtain(
eventHandler, IMAGE_REQUEST_FINISHED, j, 0, drawable));
} catch (Exception e) {
eventHandler.sendMessage(Message.obtain(
eventHandler, IMAGE_REQUEST_FAILED, j, 0));
}
}
}).start();
代码示例来源:origin: ckcz123/PKUHelper-Android
@Override
public void run() {
// TODO Auto-generated method stub
PKUHoleActivity pku = PKUHoleActivity.pkuHoleActivity;
Drawable drawable = pku.getResources().getDrawable(R.drawable.failure);
try {
InputStream inputStream = WebConnection.connect(imageUrls.get(j));
drawable = Drawable.createFromStream(inputStream, j + ".png");
} catch (Exception e) {
}
pku.eventHandler.sendMessage(Message.obtain(
pku.eventHandler, Constants.MESSAGE_PKUHOLE_IMAGE_REQUEST,
j + 1, 0, drawable));
}
}).start();
代码示例来源:origin: ckcz123/PKUHelper-Android
@Override
public void run() {
EventHandler eventHandler = LostFoundActivity.lostFoundActivity.eventHandler;
try {
InputStream inputStream = WebConnection.connect(_url);
Drawable drawable = Drawable.createFromStream(inputStream, _url);
eventHandler.sendMessage(Message.obtain(eventHandler,
Constants.MESSAGE_LOSTFOUND_IMAGE_REQUEST_FINISHED,
new Image(_id, _url, drawable)));
} catch (Exception e) {
eventHandler.sendMessage(Message.obtain(eventHandler,
Constants.MESSAGE_LOSTFOUND_IMAGE_REQUEST_FAILED,
new Image(_id, _url, null)));
}
}
}).start();
内容来源于网络,如有侵权,请联系作者删除!