〔Android程序开发〕^爱情橡皮擦^小演示


浏览:318 次

6.爱情橡皮擦“小演示

为什么它被称为“爱情橡皮擦”小演示?因为我发现了两张恋人的照片。跑步效果是:在抹去上面覆盖的恋人后,另一半会出现~~

演示想法:使用透明颜色替换原始图像的像素,立即获得替换后的图像,并在ImageView上显示图像

xmlns:app=“https://schemas.android.com/apk/res-auto "

xmlns:tools=“https://schemas.android.com/tools "

android:layout_width=“match_parent”

android:layout_height=“match_parent”

工具:context=“.MainActivity”

机器人:id=“@+id/fl_main”>

//背景图片

<图像视图

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:src=“@drawable/c”>

//操作后显示图片

<图像视图

android:id=“@+id/iv_foreground”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

>

公共类MainActivity扩展了AppCompatActivity{

ImageView前景;

位图组织位图;

位图副本位图;

帆布帆布;

油漆;

@覆盖

protected void onCreate(Bundle savedInstanceState){

super.onCreate(savedInstanceState);

//配置界面

setContentView(R.layout.activity_main);

//在容器视图中查找图片视图控件

//按Id查找视图

前景=findViewById(R.id.iv_foreground);

//读取要操作的图像位图

//位图工厂管理位图

//DecodeResource从项目资源路径生成位图

//获取资源获取项目资源

//R.可拉伸。xiugai访问资源路径下可绘制文件中的文件

orgBitmap=位图工厂。解码资源(getResources(),R.drawable.b);

//操作此图片以替换为透明颜色

//原始图纸无法操作,只能复制一份

copyBitmap=位图.createBitmap(orgBitmap.getWidth(),orgBitmap。获取高度(),orgBitmap.getConfig());

//创建画布画布

canvas=新画布(copyBitmap);

//创建笔刷

油漆=新油漆();

//创建矩阵

矩阵矩阵=新矩阵();

//旋转图片

//matrix.setRotate(90240400);

//翻译

//matrix.setTranslate(100,0);

//翻转设置动作一次,多次后操作

//matrix.setScale(0.5f,1f);

//matrix.postTranslate(orgBitmap.getWidth(),0);

//画一幅画

帆布drawBitmap(orgBitmap,矩阵,绘制);

//显示图片

前景.setImageBitmap(copyBitmap);

//将触摸事件添加到前景图像

//当触摸事件发生时,系统将监视并回调该事件

前景。setOnTouchListener(新视图.OnTouchListiner(){

@覆盖

public boolean onTouch(查看视图,MotionEvent MotionEvent){

//获取当前事件

int action=motionEvent.getAction();

//判断状态

如果(action==MotionEvent.action_MOVE){

//获取触摸点的坐标

int x=(int)motionEvent.getX();

int y=(int)motionEvent.getY();

对于(整数i=0;i<100;i++){

对于(int j=0;j<200;j++){

复制位图.setPixel(

相关资讯:
APP项目开发流程

APP项目开发流程

查看
软件外包开发过程

软件外包开发过程

查看
软件外包项目开发过程

软件外包项目开发过程

查看
如何找到一家满意的软件项目外包公司

如何找到一家满意的软件项目外包公司

查看
寻找优质APP外包公司

寻找优质APP外包公司

查看