«

android 图形平移 镜子效果 倒影效果

时间:2024-3-2 19:42     作者:韩俊     分类: Android


图形平移

setTranslate(1.5f,-10);


镜子效果

matrix.setScale(-1, 1);

matrix.postTranslate(bmp.getWidth(),0);


倒影效果

matrix.setScale(1, -1);

matrix.postTranslate(0, bmp.getHeight());


-----------------------------------------------------


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 source = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), bitmap.getConfig());
Matrix matrix = new Matrix();


//把x轴的值 变成负的
matrix.setScale(1, -1);
matrix.postTranslate(0, source.getHeight());


Bitmap baseBitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, false);

Canvas canvas = new Canvas(baseBitmap);

canvas.drawBitmap(bitmap, matrix, new Paint());
iv_dest.setImageBitmap(baseBitmap);


}


}


整理自ppt 源码


标签: android

热门推荐