当前位置 : 主页 > 编程语言 > java >

图像的倒影镜像处理

来源:互联网 收集:自由互联 发布时间:2021-06-28
DaoYingActivity.java package com.example.rootimage;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Matrix;import android.graphics.Pain
DaoYingActivity.java
package com.example.rootimage;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class DaoYingActivity extends AppCompatActivity {
    private ImageView YuanTu,change;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dao_ying);
        YuanTu=findViewById(R.id.YuanTu);
        change=findViewById(R.id.change);
    }
    public void DaoYing(View view){
        Bitmap SrcBitmap = BitmapFactory.decodeFile("mnt/sdcard/img2.png");//插入文件路径
        YuanTu.setImageBitmap(SrcBitmap);
        Bitmap CopyBitmap = Bitmap.createBitmap(SrcBitmap.getWidth(), SrcBitmap.getHeight(), SrcBitmap.getConfig());//临摹原图
        Canvas canvas = new Canvas(CopyBitmap);//创建画布
        Paint paint=new Paint();//创建画笔
        paint.setColor(Color.BLUE);
        Matrix matrix=new Matrix();//matrix是矩阵的意思
        matrix.setScale(1,-1);//原图横坐标不变,纵坐标取反
        matrix.postTranslate(0,SrcBitmap.getHeight());//取反后在纵向移动原图的高
        canvas.drawBitmap(SrcBitmap,matrix,paint);
        change.setImageBitmap(CopyBitmap);
    }
}
MirrorActivity.java
package com.example.rootimage;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;

public class MirrorActivity extends AppCompatActivity {
    private ImageView YuanTu,change;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mirror);
        YuanTu= findViewById(R.id.YuanTu);
        change=findViewById(R.id.change);
    }
    public void mirror(View view){
        Bitmap SrcBitmap = BitmapFactory.decodeFile("mnt/sdcard/img3.png");
        YuanTu.setImageBitmap(SrcBitmap);
        Bitmap mirrorBitmap = Bitmap.createBitmap(SrcBitmap.getWidth(), SrcBitmap.getHeight(), SrcBitmap.getConfig());
        Canvas canvas=new Canvas(mirrorBitmap);
        Paint paint=new Paint();
        paint.setColor(Color.BLACK);
        Matrix matrix=new Matrix();
        matrix.setScale(-1,1);
        matrix.postTranslate(SrcBitmap.getWidth(),0);//实现镜像效果,postTranslate方法在原有变换上再加以变换。
        canvas.drawBitmap(SrcBitmap,matrix,paint);
        change.setImageBitmap(mirrorBitmap);
    }
}
activity_dao_ying.xml
 

 

    
  

    
   
    
     
     
    
  


 
activity_mirror.xml
上一篇:spark执行参数分析
下一篇:FastJson.java
网友评论