Android圖像變化
阿新 • • 發佈:2017-07-03
android圖像變化
暫時不需要研究具體詳細的怎麽實現過程,直接使用已有的方法即可,代碼如下
package com.yuanlp.testimage; 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); } }
本文出自 “YuanGuShi” 博客,請務必保留此出處http://cm0425.blog.51cto.com/10819451/1943888
Android圖像變化