首页 > 代码库 > Android图像变化
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图像变化
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。