一对一视频聊天软件源码,实现擦除和点击亮灯效果

一对一视频聊天软件源码,实现擦除和点击亮灯效果,第1张

概述一对一视频聊天软件源码,实现擦除和点击亮灯效果实现的相关代码自定义View代码:packagecom.example.workday05;importandroid.content.Context;importandroid.graphics.Bitmap;importandroid.graphics.BitmapFactory;importandroid.graphics.Canvas;importandroi @H_301_3@

一对一视频聊天软件源码,实现擦除和点击亮灯效果实现的相关代码
自定义view代码:

package com.example.workday05;import androID.content.Context;import androID.graphics.Bitmap;import androID.graphics.BitmapFactory;import androID.graphics.Canvas;import androID.graphics.color;import androID.graphics.Paint;import androID.graphics.Path;import androID.graphics.PorterDuff;import androID.graphics.PorterDuffXfermode;import androID.util.AttributeSet;import androID.util.displayMetrics;import androID.vIEw.MotionEvent;import androID.vIEw.VIEw;import androID.vIEw.WindowManager;public class Demo1 extends VIEw {    private Paint paint;    private Canvas mycanvas;    private Context context;    private int wIDth;    private int height;    private Bitmap fgbitmap;    private Bitmap bgbitmap;    private Path path;    private WindowManager manager;    public Demo1(Context context, AttributeSet attrs) {        super(context, attrs);        this.context = context;        initPaint();    }    private voID initPaint() {        paint = new Paint();        //获取窗口的大小        manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);        displayMetrics displayMetrics = new displayMetrics();        manager.getDefaultdisplay().getMetrics(displayMetrics);        //获取到宽高        wIDth = displayMetrics.wIDthPixels;        height = displayMetrics.heightPixels;        //设置画笔的属性        paint.setAntiAlias(true);//抗锯齿        paint.setDither(true);//抗抖动        //设置透明度        paint.setARGB(128,255,0,0);        //设置混合模式        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));        //设置 描边        paint.setStyle(Paint.Style.stroke);        //设置宽度        paint.setstrokeWIDth(40);        //设置路径结合处样式        paint.setstrokeJoin(Paint.Join.ROUND);        //设置笔触类型        paint.setstrokeCap(Paint.Cap.ROUND);        //生成灰色前景        fgbitmap = Bitmap.createBitmap(wIDth, height, Bitmap.Config.ARGB_8888);        //将其注入画布        mycanvas = new Canvas(fgbitmap);        //设置画布为灰色        mycanvas.drawcolor(color.GRAY);        //生成背景图片        bgbitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.demo1);        //剪切成屏幕大小        bgbitmap = Bitmap.createScaledBitmap(bgbitmap,wIDth,height,true);        //创建path对象        path = new Path();    }    @OverrIDe    public boolean ontouchEvent(MotionEvent event) {        switch(event.getAction()){            case MotionEvent.ACTION_DOWN:                path.reset();//清除之前的路径                path.moveto(event.getX(),event.getY());                break;            case MotionEvent.ACTION_MOVE:                path.lineto(event.getX(),event.getY());                break;            case MotionEvent.ACTION_UP:                path.lineto(event.getX(),event.getY());                break;        }        invalIDate();        return true;    }    @OverrIDe    protected voID onDraw(Canvas canvas) {        super.onDraw(canvas);        //设置背景图片        canvas.drawBitmap(bgbitmap,0,0,null);        //设置前景灰色背景        canvas.drawBitmap(fgbitmap,0,0,null);        //手指划过的路径        mycanvas.drawPath(path,paint);    }}

布局代码:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    xmlns:tools="http://schemas.androID.com/tools"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    tools:context=".workday5"    androID:orIEntation="vertical"    >    <com.example.workday05.Demo1        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:ID="@+ID/demo1"        /></linearLayout>

点击亮灯效果:
java代码:

package com.example.day05;import androID.annotation.Suppresslint;import androID.content.Context;import androID.graphics.Canvas;import androID.graphics.color;import androID.graphics.Paint;import androID.graphics.Path;import androID.graphics.Point;import androID.graphics.RectF;import androID.graphics.Region;import androID.util.AttributeSet;import androID.util.displayMetrics;import androID.vIEw.MotionEvent;import androID.vIEw.VIEw;import androID.vIEw.WindowManager;public class MyVIEw2 extends VIEw {    private Paint paint;    private Paint paint1;    private Paint paint2;    private Paint paint3;    private Path path;    private Path path1;    private Path path2;    private Path path3;    private Context context;    public MyVIEw2(Context context,AttributeSet attrs) {        super(context, attrs);        this.context = context;        initPaint();    }    private voID initPaint() {        //四个画笔        paint = new Paint();        paint1 = new Paint();        paint2 = new Paint();        paint3 = new Paint();        //四个路径        path = new Path();        path1 = new Path();        path2 = new Path();        path3 = new Path();        //第一个画笔        paint.setcolor(color.RED);        paint.setstrokeWIDth(2);        paint.setstrokeWIDth(5);        paint.setStyle(Paint.Style.stroke);        //第二个画笔        paint1.setcolor(color.BLUE);        paint1.setstrokeWIDth(2);        paint1.setstrokeWIDth(5);        paint1.setStyle(Paint.Style.stroke);        //第三个画笔        paint2.setcolor(color.GREEN);        paint2.setstrokeWIDth(2);        paint2.setstrokeWIDth(5);        paint2.setStyle(Paint.Style.stroke);        //第四个画笔        paint3.setcolor(color.GRAY);        paint3.setstrokeWIDth(2);        paint3.setstrokeWIDth(5);        paint3.setStyle(Paint.Style.stroke);    }    @OverrIDe    protected voID onSizeChanged(int w, int h, int olDW, int oldh) {        super.onSizeChanged(w, h, olDW, oldh);    }    int height;    int wIDth;    @OverrIDe    protected voID onDraw(Canvas canvas) {        super.onDraw(canvas);        path.moveto(0,0);         WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);        displayMetrics displayMetrics = new displayMetrics();        manager.getDefaultdisplay().getMetrics(displayMetrics);        //获取主屏幕的宽与高        height = displayMetrics.heightPixels;        wIDth = displayMetrics.wIDthPixels;        path.lineto(wIDth/2,height/2);        path.lineto(wIDth,0);        canvas.drawPath(path,paint);        path1.moveto(wIDth,height);        path1.lineto(wIDth/2,height/2);        path1.lineto(wIDth,0);        canvas.drawPath(path1,paint1);        path2.moveto(wIDth,height);        path2.lineto(wIDth/2,height/2);        path2.lineto(0,height);        canvas.drawPath(path2,paint2);        path3.moveto(0,height);        path3.lineto(wIDth/2,height/2);        path3.lineto(0,0);        canvas.drawPath(path3,paint3);    }    float x;    float y;    private int PicX;    private int PicY;    @OverrIDe    public boolean ontouchEvent(MotionEvent event) {        //获取XY的坐标        x = event.getX();        y = event.getY();        switch (event.getAction()){            case MotionEvent.ACTION_DOWN:                //点击区域的判断方法                ClickRegion();                break;            case MotionEvent.ACTION_MOVE:                break;            case MotionEvent.ACTION_UP:                break;        }        invalIDate();        return true;    }    private voID ClickRegion() {        PicX = (int) x;        PicY = (int) y;        //创建一个矩形        RectF rectF = new RectF();        path.computeBounds(rectF,true);//用path分割成矩形        Region region = new Region();//区域        //构造新区域        region.setPath(path,new Region((int) rectF.left,(int)rectF.top,(int)rectF.right,(int)rectF.bottom));        boolean b = region.contains(PicX, PicY);        if(b){            paint.setStyle(Paint.Style.FILL);        }        //创建一个矩形        RectF rectF1 = new RectF();        path1.computeBounds(rectF1,true);//用path分割成矩形        Region region1 = new Region();//区域        //构造新区域        region1.setPath(path1,new Region((int) rectF1.left,(int)rectF1.top,(int)rectF1.right,(int)rectF1.bottom));        boolean b1 = region1.contains(PicX, PicY);        if(b1){            paint1.setStyle(Paint.Style.FILL);        }        //创建一个矩形        RectF rectF2 = new RectF();        path2.computeBounds(rectF2,true);//用path分割成矩形        Region region2 = new Region();//区域        //构造新区域        region2.setPath(path2,new Region((int) rectF2.left,(int)rectF2.top,(int)rectF2.right,(int)rectF2.bottom));        boolean b2 = region2.contains(PicX, PicY);        if(b2){            paint2.setStyle(Paint.Style.FILL);        }        //创建一个矩形        RectF rectF3 = new RectF();        path3.computeBounds(rectF3,true);//用path分割成矩形        Region region3 = new Region();//区域        //构造新区域        region3.setPath(path3,new Region((int) rectF3.left,(int)rectF3.top,(int)rectF3.right,(int)rectF3.bottom));        boolean b3 = region3.contains(PicX, PicY);        if(b3){            paint3.setStyle(Paint.Style.FILL);        }    }}

这里的代码全是复制粘贴,如有更简单的方法欢迎私信。

布局代码:<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    xmlns:tools="http://schemas.androID.com/tools"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    tools:context=".day05">    <com.example.day05.MyVIEw2        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:ID="@+ID/myvIEw"        /></relativeLayout>

主类引用:

package com.example.workday05;import androID.support.v7.app.AppCompatActivity;import androID.os.Bundle;public class Activity_second extends AppCompatActivity {    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_second);        Demo2 demo2 = findVIEwByID(R.ID.demo2);    }}

以上就是 一对一视频聊天软件源码,实现擦除和点击亮灯效果实现的相关代码,更多内容欢迎关注之后的文章

总结

以上是内存溢出为你收集整理的一对一视频聊天软件源码,实现擦除和点击亮灯效果全部内容,希望文章能够帮你解决一对一视频聊天软件源码,实现擦除和点击亮灯效果所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1042988.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存