用到的api:
Matrix matrix = new Matrix();
matrix.setValues(new float[] {
1, 0, 0,
0, 1, 0,
0, 0, 1
});
x = 1x + 0y + 0z
y = 0x + 1y + 0z
z = 0x + 0y + 1z
通过canvas.drawBitmap(bmp, matrix, paint);创建bitmap
1.水平缩放0.5
2.垂直拉扯2倍
matrix.setScale(1.5f,1);//水平点放大到1.5f,垂直1
---------------------------------------------------
Activity 代码如下:
public class MainActivity extends Activity {
private ImageView iv_src;
private ImageView iv_dest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv_src = (ImageView) findViewById(R.id.iv_src);
iv_src.setImageBitmap(BitmapFactory.decodeFile("/sdcard/tom.png"));
iv_dest = (ImageView) findViewById(R.id.iv_dest);
}
public void click(View view) {
Bitmap bitmap = BitmapFactory.decodeFile("/sdcard/tom.png");
Bitmap baseBitmap = Bitmap.createBitmap(bitmap.getWidth()*2,
bitmap.getHeight()/2, bitmap.getConfig());
Canvas canvas = new Canvas(baseBitmap);
Matrix matrix = new Matrix();
/* matrix.setValues(new float[] {
2, 0, 0,
0, 0.5f, 0,
0, 0, 1
});*/
matrix.setScale(2.0f, 0.5f);
canvas.drawBitmap(bitmap, matrix, new Paint());
iv_dest.setImageBitmap(baseBitmap);
}
}
整理自ppt和源码