【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
推荐阅读
- Win8系统IE浏览器缓存设置办法介绍
- Android 开源框架Universal-Image-Loader全然解析--- 基本介绍及使用
- android Service中启动Dialog
- Android开源框架ViewPageIndicator和ViewPager实现Tab导航
- android graphic(15)—fence
- Android Application Digital Signatures - Android 数字签名
- Android中Handler的使用
- 使用fiddler获取手机app端接口地址
- Android之使用MediaMetadataRetriever类获取视频第一帧