package com.example.demo; import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.view.Menu;
import android.widget.ImageView; public class MainActivity extends Activity { private ImageView imageView01,imageView02;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView01=(ImageView) findViewById(R.id.imageView1);
imageView02=(ImageView) findViewById(R.id.imageView2);
//设置imageview01
Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
imageView01.setImageBitmap(bitmap); Bitmap alertBitmap=Bitmap.createBitmap(bitmap.getWidth()*2, bitmap.getHeight(), bitmap.getConfig());
Canvas canvas=new Canvas(alertBitmap);//设置画布大小 Matrix matrix=new Matrix();
matrix.setScale(2.0f, 1.0f);
/*
* matrix.setValues(new float[]{
2.0f,0,0,
0,1,0,
0,0,1
});
*/
Paint paint=new Paint();
canvas.drawBitmap(bitmap, matrix, paint);
imageView02.setImageBitmap(alertBitmap); } @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
} }
镜面效果
matrix.setScale(-1, 1);
matrix.postTranslate(bitmap.getWidth(), 0);
倒影效果