-1
我在android中将relativelayout转换为位图时遇到了一个问题。问题:在Android中将Relativelayout转换为位图
在onCreate()中,我已经将相关布局转换为位图。 (相关布局包括imageview和其他视图) 然后,我想在更改ImageView的图像后再次将relavielayout转换为位图。 但结果与上次转换后的图像结果相同。
代码:
v = (RelativeLayout) findViewById(R.id.relative_layout_id);
v.setDrawingCacheEnabled(true);
v.measure(View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, view.MeasureSpec.UNSPECIFIED));
v.layout(0, 0, share_screen.getMeasuredWidth(), share_screen.getHeight());
v.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(share_screen.getDrawingCache());
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.PNG, 100, bytes);
image_view.setImageBitmap(b);
http://stackoverflow.com/a/8120310/3209739 – cgr