这是我用来在ActivityInstrumentationTestCase2
final Bitmap img = ((BitmapDrawable) getActivity().getResources().getDrawable(R.drawable.my_drawable)).getBitmap();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
View view = new View(getActivity()) {
@Override
protected void onDraw(Canvas canvas) {
canvas.scale(1f, -1f);
canvas.translate(0, -canvas.getClipBounds().height());
canvas.drawBitmap(img, 0, 0, null);
}
};
getActivity().setContentView(view);
}
});
Thread.sleep(2000);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
View view = new View(getActivity()) {
@Override
protected void onDraw(Canvas canvas) {
canvas.scale(1f, -0.9f);
canvas.drawBitmap(img, 0, 0, null);
}
};
getActivity().setContentView(view);
}
});
Thread.sleep(2000);
在第一种情况下,图像沿x轴镜像校正,但在第二种情况下,应用比例因子而不镜像图像。
我错过了什么,或者这是一个错误?