android之图像的操作
来源:互联网 发布:淘宝充话费很久不到账 编辑:程序博客网 时间:2024/09/21 11:16
要想处理图像,必须经过以下步骤:
1.拿到原图
2.拿到一张与原图相同的纸
3.然后将这张纸固定在画板上
4.找一根画笔
5.按照一定规则处理原图图片
6.将处理过的图片用画笔画出来
代码编写:
布局:
<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"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="操作图片" android:onClick="btn"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/iv1" android:src="@drawable/img_small_1"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/iv2" android:background="#000000"/></LinearLayout>activity:
public class MainActivity extends Activity {private ImageView iv2;//原图private Bitmap baseBitmap;//画纸private Bitmap copyBitmap;//画板private Canvas canvas;//画笔private Paint paint;public void btn(View view) {// TODO Auto-generated method stub//拿到原图baseBitmap=BitmapFactory.decodeResource(getResources(), R.drawable.img_small_1);//1.先拿到一张与原图相同的纸 copyBitmap=Bitmap.createBitmap(baseBitmap.getWidth(), baseBitmap.getHeight(), baseBitmap.getConfig());//2.然后将这张纸固定在画板上 canvas=new Canvas(copyBitmap);//3.找一根画笔 paint=new Paint();//4.按照一定规则处理原图图片 Matrix matrix=new Matrix();//1:1 //缩放 //matrix.setScale(0.5f, 0.5f); //位移 //matrix.setTranslate(50f, 50f); //旋转 //matrix.setRotate(45);//顺时针旋转45度,默认以左上角为原点 //matrix.setRotate(45, baseBitmap.getWidth()/2, baseBitmap.getHeight()/2);//沿中心点旋转 //镜面效果 matrix.setScale(-1f, 1f); //matrix.setTranslate(baseBitmap.getWidth(),0); matrix.postTranslate(baseBitmap.getWidth(), 0);//如果要对图片进行多次操作,要用postTranslate //倒影 matrix.setScale(1f, -1f); matrix.postTranslate(0, baseBitmap.getHeight());//5.将处理过的图片用画笔画出来canvas.drawBitmap(baseBitmap, matrix, paint);iv2.setImageBitmap(copyBitmap);}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);iv2=(ImageView) findViewById(R.id.iv2);}}
效果图:
0 0
- android之图像的操作
- Android 对图像的操作
- android学习笔记之图像像素操作
- canvas学习之图像的基本操作
- GDI+之图像操作
- android 操作图像像素
- Android游戏Graphics绘图之图像像素操作
- Android游戏Graphics绘图之图像像素操作
- Android|图像图像之Xfermode
- Android|图像图像之gradient
- Android|图像图像之PorterDuff
- Android 图像绘制之Matrix 的使用
- Android学习之图像的处理
- Android 关于SD卡操作 之 SD卡文件浏览器和存取SD卡上的图像
- matlab+数字图像处理教程之1-图像的基本操作
- Python之图像的基本操作和处理
- android开发笔记之多媒体—图像的操作
- 图像的ROI操作
- spring3.0以后移除ContextLoaderServlet,使用ContextLoaderListener获取ApplicationContext
- matlab排序函数
- 有关KeyStore的问题
- ThinkPHP3.2.3 - 课程总笔记
- 电压跟随器
- android之图像的操作
- 多维数组与指针简析
- OpenGL非规则多边形(凹多边形,凸多边形)二维纹理映射(填充)
- 通过资源的名称获取资源id
- MPEG2音视频同步AVS
- mongodb原子操作
- linux命令 tail
- [Google 2017 Apac] Robot Rock Band
- 多字段表单POST时,数据被截断问题,原因是max_input_vars限制