Android把view的画面转换为bitmap
ImageView iv = (ImageView) findViewById(R.id.ImageView01); ImageView iv2 = (ImageView) findViewById(R.id.ImageView02); ImageView iv3 = (ImageView) findViewById(R.id.ImageView03); //draw的方式对整屏截取,但信息栏为黑色 View cv = getWindow().getDecorView(); Bitmap b = Bitmap.createBitmap(200, 200, Bitmap.Config.RGB_565); cv.draw(new Canvas(b)); iv.setImageBitmap(b); //对隐藏的未画过的对象,截出的是黑色 Bitmap image = Bitmap.createBitmap(200, 200, Bitmap.Config.RGB_565); bt3.draw(new Canvas(image)); iv2.setImageBitmap(image); //get drawable cache , bitmap to drawable bt4.setDrawingCacheEnabled(true); Bitmap bitmap = bt4.getDrawingCache(); Drawable drawable = (Drawable) new BitmapDrawable(bitmap); iv3.setBackgroundDrawable(drawable);
上面方法如果不好使:
Bitmap oriBitmap = BitmapFactory.decodeResource(mContext.getResources(), mContext.getResources().getIdentifier("icon_" + app.sortId, "drawable", mContext.getPackageName()));
最后更新:2017-04-02 15:15:24