Android把view的画面转换为bitmap
2010-11-05 00:55:00 来源:WEB开发网核心提示:Java代码ImageView iv = (ImageView) findViewById(R.id.ImageView01);ImageView iv2 = (ImageView) findViewById(R.id.ImageView02);ImageView iv3 = (ImageView) findViewB
Java代码
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);
[]
更多精彩
赞助商链接