`

some common usefull convertings.

阅读更多
Convert Drawable to bitmap:
Bitmap icon= BitmapFactory.decodeResource(context.getResources(),
                    R.drawable.icon_resource);

Convert Bitmap to drawable:
Drawable d =new BitmapDrawable(bitmap);

Convert imageview to bitmap:
ImageView image=new ImageView(context);
 Bitmap viewBitmap = Bitmap.createBitmap(i.getWidth(),i.getHeight(),Bitmap.Config.ARGB_8888);//i is imageview which u want to convert in bitmap
Canvas canvas = new Canvas(viewBitmap);
 
image.draw(canvas);

Convert List to String[]:
static String[] convert(List<String[]> from) {
        ArrayList<String> list = new ArrayList<String>();
        for (String[] strings : from) {
            Collections.addAll(list, strings);
        }
        return list.toArray(new String[list.size()]);
    }

Convert seconds to date time string:
SimpleDateFormat formatter = new SimpleDateFormat("EEEE, MMMM d, yyyy HH:mm");
String dateString = formatter.format(new Date(seconds * 1000L));
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics