Android从RelativeLayout创建位图ChildView没有正确的scalling

时间:2016-09-24 18:16:23

标签: android bitmap relativelayout

以下是将视图转换为位图的代码。

public static Bitmap loadBitmapFromView(View v) {
v.measure(View.MeasureSpec.makeMeasureSpec(v.getLayoutParams().width, View.MeasureSpec.EXACTLY),
        View.MeasureSpec.makeMeasureSpec(v.getLayoutParams().height, View.MeasureSpec.EXACTLY));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.RGB_565);
Canvas c = new Canvas(b);
v.draw(c);
return b;

}

以上代码正确创建实际大小的位图。但是所有子位置都没有按布局比例缩放。

0 个答案:

没有答案