• 图片缩放,旋转,平移,镜面效果,倒影效果,图片合成


    package com.example.test;
    
    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.widget.ImageView;
    
    public class TestBitmap2 extends AppCompatActivity {
    private ImageView mIv1,mIv2;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_test_bitmap2);
            mIv1= (ImageView) findViewById(R.id.iv_bit1);
            mIv2= (ImageView) findViewById(R.id.iv_bit2);
            Bitmap bitmap1= BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher);
            mIv1.setImageBitmap(bitmap1);
    
            Bitmap bitmap2=Bitmap.createBitmap(bitmap1.getWidth(),bitmap1.getHeight(),bitmap1.getConfig());
            Canvas canvas=new Canvas(bitmap2);
            Paint paint=new Paint();
            paint.setColor(Color.BLACK);
            Matrix matrix=new Matrix();
    
            //图片缩放
           /* matrix.setValues(new float[]{
                    0.5f,0,0,
                    0,0.5f,0,
                    0,0,1
            });*/
    
            //图片旋转
           // matrix.setRotate(180,bitmap1.getWidth()/2,bitmap1.getHeight()/2);
          /*  matrix.setRotate(15);
            paint.setAntiAlias(true);//消除锯齿*/
    
            //图片平移
            matrix.setTranslate(10,10);//水平和竖直方向移动10个像素
    
            //镜子效果
          /*  matrix.setScale(-1,1);
            matrix.postTranslate(bitmap1.getWidth(),0);*/
    
            //倒影效果
           /* matrix.setScale(1,-1);
            matrix.postTranslate(0,bitmap1.getHeight());
            canvas.drawBitmap(bitmap1,matrix,paint);*/
    
            mIv2.setImageBitmap(bitmap2);
    
    
        }
    }
    package com.example.test;
    
    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.graphics.PorterDuff;
    import android.graphics.PorterDuffXfermode;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.widget.ImageView;
    
    public class TestBitmap3 extends AppCompatActivity {
    private ImageView mIv;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_test_bitmap3);
            mIv= (ImageView) findViewById(R.id.iv_bit3);
            //图片合成画布,   先画图片A,再画图片B
            Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.drawable.ic_guide_1);
            Bitmap alterBitmap=Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(),bitmap.getConfig());
            Canvas canvas=new Canvas(alterBitmap);
            Paint paint=new Paint();
            paint.setColor(Color.BLACK);
            paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DARKEN));//设置图形的混合模式
            canvas.drawBitmap(bitmap,new Matrix(),paint);
            Bitmap ic_luncher=BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher);
            canvas.drawBitmap(ic_luncher,new Matrix(),paint);
            mIv.setImageBitmap(alterBitmap);
        }
    }
  • 相关阅读:
    V4L2摄像头应用编程(转)
    ok6410 3.0.1内核调用V4L接口出错解决方法(转)
    Salesforce学习之路(十一)Aura组件属性<aura:attribute />
    Salesforce学习之路(九)Org的命名空间
    Salesforce学习之路(八)一次拉取多个文件或全部文件至本地
    Salesforce学习之路(十)Aura组件工作原理
    Salesforce学习之路(七)Visualforce结合Reports展示图表
    Salesforce学习之路(六)利用Visualforce Page实现页面的动态刷新功能
    Salesforce学习之路(五)role hierarchy & sharing
    Salesforce学习之路(四)利用Jenkins和Git实现Salesforce的CI/CD功能
  • 原文地址:https://www.cnblogs.com/jiang2538406936/p/6029141.html
Copyright © 2020-2023  润新知