Android Bitmap缩放
来源:互联网 发布:ubuntu root用户提权 编辑:程序博客网 时间:2024/06/05 16:12
Matrix matrix = new Matrix();
matrix.setValues(new float[] {
1, 0, 0,
0, 1, 0,
0, 0, 1
});
x = 1x + 0y + 0z
y = 0x + 1y + 0z
z = 0x + 0y + 1z
通过canvas.drawBitmap(bmp, matrix, paint);创建bitmap
1.水平缩放0.5
2.垂直拉扯2倍
matrix.setScale(1.5f,1);//水平点放大到1.5f,垂直1
activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="click" android:text="拷贝一个位图" /> <ImageView android:id="@+id/iv1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageView android:id="@+id/iv2" android:layout_width="wrap_content" android:layout_height="wrap_content" /></LinearLayout>
public class MainActivity extends Activity { private ImageView iv1,iv2; private Bitmap alterBitmap; private Bitmap srcBmp; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv1 = (ImageView) findViewById(R.id.iv1); iv2 = (ImageView) findViewById(R.id.iv2); //给第一个imageview默认设置一个位图 srcBmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); iv1.setImageBitmap(srcBmp); //创建原图的一个副本。 可修改 创建的是一个空白的图形。 alterBitmap = Bitmap.createBitmap(srcBmp.getWidth()*2, srcBmp.getHeight()*2,srcBmp.getConfig()); } /** * 创建原图 bm的一个拷贝。副本 * @param view */ public void click(View view){ //1.准备一个画板 在上面放上准备好的 空白的位图 Canvas canvas = new Canvas(alterBitmap); //2.准备一个画笔 Paint paint = new Paint(); paint.setColor(Color.BLACK); //3.画画 Matrix m = new Matrix(); m.setScale(2.0f, 2.0f);//放大为原来的4倍 canvas.drawBitmap(srcBmp, m, paint); iv2.setImageBitmap(alterBitmap);//把原图的副本设置到界面上。 }}
参考:
Android图片处理
0 0
- android bitmap缩放
- android Bitmap缩放
- Android Bitmap缩放
- Android 缩放bitmap的函数
- android Bitmap 读取缩放图片
- Android 之 Bitmap等比缩放
- android ImagView缩放方法之一(Bitmap)
- android 中bitmap 缩放和阴影效果
- Android Bitmap转换以及图片的缩放
- Android中图片Bitmap的缩放
- android Bitmap的截取及缩放
- Android bitmap 图片缩放,压缩处理
- Android中图片Bitmap的缩放
- Android中bitmap图像的缩放
- Android中图片Bitmap的缩放
- Android中图片Bitmap的缩放
- Android Bitmap精确缩放到指定大小
- Bitmap缩放
- Bootstrap实现基于carousel.js框架的轮播图效果(无过渡动画)
- Eclipse neon中集成Tomcat
- Faster-RCNN算法精读
- 河南工业“玲珑杯”ch追妹
- C++基础之栈篇
- Android Bitmap缩放
- 从国企到阿里的面试经历(一)
- Java 套接字
- matlab基本矩阵操作
- LIS 最长上升子序列问题 O(n^2)
- Nodejs笔记1
- ~求二叉树中最远的两个节点的距离~
- WebLogic和Tomcat浅谈
- 《C语言及程序设计》教学视频 <18 链表中结点的插入和删除> 示例代码