短視訊原始碼,每日任務通過刮卡的方式選擇

zhibo系統開發發表於2022-01-25

短視訊原始碼,每日任務通過刮卡的方式選擇,刮卡動畫實現的相關程式碼

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="
xmlns:app="
xmlns:tools="
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bk"
tools:context=".MainActivity">
    <ImageView
        android:id="@+id/bg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bg"/>
    <ImageView
        android:id="@+id/imgv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/scratch_card"/>
</RelativeLayout>

MainActivity.java

package com.example.service;
import androidx.appcompat.app.AppCompatActivity;
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.text.Html;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CalendarView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ImageView;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
    private ImageView imageView;
    private Bitmap alterBitmap;
    private double nX,nY;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imageView=(ImageView) findViewById(R.id.imgv);
        Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.drawable.scratch_card);
        alterBitmap=Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(),bitmap.getConfig());
        DisplayMetrics dm=new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        nX=(double) bitmap.getWidth()/dm.widthPixels;
        nY=(double) bitmap.getHeight()/dm.heightPixels;
        Canvas canvas=new Canvas(alterBitmap);
        Paint paint=new Paint();
        paint.setColor(Color.BLACK);
        paint.setAntiAlias(true);
        Matrix matrix=new Matrix();
        canvas.drawBitmap(bitmap,matrix,paint);
        imageView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                try{
                    int x=(int) event.getX();
                    int y=(int) event.getY();
                    for(int i=-100;i<100;i++){
                        for(int j=-100;i<100;i++){
                            if(Math.sqrt((i*i)+(j*j))<=100){
                                alterBitmap.setPixel((int)(x*nX)+i,(int)(y*nY+90)+j,Color.TRANSPARENT);
                            }
                        }
                    }
                    imageView.setImageBitmap(alterBitmap);
                }catch (Exception e){
                    e.printStackTrace();
                }
                return true;
            }
        });
    }
}

以上就是短視訊原始碼,每日任務通過刮卡的方式選擇,刮卡動畫實現的相關程式碼, 更多內容歡迎關注之後的文章


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2853949/,如需轉載,請註明出處,否則將追究法律責任。

相關文章