Drawable をビットマップに変換するにはどうすればいいですか? 質問する

Drawable をビットマップに変換するにはどうすればいいですか? 質問する

Drawable特定のものをデバイスの壁紙として設定したいのですが、すべての壁紙機能は s のみを受け入れます。2.1より前のバージョンなのでBitmap使用できません。WallpaperManager

また、私のドローアブルは Web からダウンロードされ、 には存在しませんR.drawable

ベストアンサー1

このコードは役に立ちます。

Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
                                           R.drawable.icon_resource);

こちらは画像がダウンロードされるバージョンです。

String name = c.getString(str_url);
URL url_value = new URL(name);
ImageView profile = (ImageView)v.findViewById(R.id.vdo_icon);
if (profile != null) {
    Bitmap mIcon1 =
        BitmapFactory.decodeStream(url_value.openConnection().getInputStream());
    profile.setImageBitmap(mIcon1);
}

おすすめ記事