Android图像变化
发表于:2024-11-27 作者:热门IT资讯网编辑
编辑最后更新 2024年11月27日,暂时不需要研究具体详细的怎么实现过程,直接使用已有的方法即可,代码如下package com.yuanlp.testp_w_picpath;import android.graphics.Bitmap
暂时不需要研究具体详细的怎么实现过程,直接使用已有的方法即可,代码如下
package com.yuanlp.testp_w_picpath;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.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.ImageView;public class MainActivity extends AppCompatActivity { private ImageView iv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv = (ImageView) findViewById(R.id.iv); } public void turnBig(View view){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.meinv); Matrix matrix=new Matrix(); matrix.setScale(2,2); //放大四倍,水平方向2倍,竖直方向2倍 //买一张纸 Bitmap bitmap1 = Bitmap.createBitmap(bitmap.getWidth() * 2, bitmap.getHeight() * 2, bitmap.getConfig()); //买个画板 Canvas canvas = new Canvas(bitmap1); //临摹会话 Paint paint = new Paint(); paint.setColor(Color.BLACK); canvas.drawBitmap(bitmap,matrix,paint); //传入新纸 iv.setImageBitmap(bitmap1); } public void turnSmall(View view){ Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.meinv); Matrix matrix=new Matrix(); matrix.setScale(0.5f,0.5f); //买个纸 Bitmap bitmap1 = Bitmap.createBitmap(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getConfig()); //买个画板 Canvas canvas=new Canvas(bitmap1); Paint paint=new Paint(); paint.setColor(Color.BLACK); canvas.drawBitmap(bitmap,matrix,paint); iv.setImageBitmap(bitmap1); }}