简体   繁体   English

用于解锁屏幕的 Android 拉链动画

[英]Android Zipper Animation for unlock screen

I am currently working on zip animation to unlock android mobile screen.我目前正在研究 zip 动画以解锁 Android 手机屏幕。 Changing background images is a expensive task and have not a smooth effect.更改背景图像是一项昂贵的任务,而且效果并不流畅。 I want a smooth effect in it.我想要一个平滑的效果。 Any help please?请问有什么帮助吗? Thanks谢谢

Try this:尝试这个:

The smooth effect makes use of Convolution Matrix:平滑效果利用了卷积矩阵:

Some image effects are better to implement using Convolution Matrix method like: Gaussian Blur, Sharpening, Embossing, Smooth…使用卷积矩阵方法可以更好地实现一些图像效果,例如:高斯模糊、锐化、浮雕、平滑……

Check That Link to know more about Convolution Matrix or Another one检查该链接以了解有关Convolution Matrix另一个Convolution Matrix更多信息

To do Convolution Matrix做卷积矩阵

import android.graphics.Bitmap;
import android.graphics.Color;

public class ConvolutionMatrix
{
    public static final int SIZE = 3;

    public double[][] Matrix;
    public double Factor = 1;
    public double Offset = 1;

    public ConvolutionMatrix(int size) {
        Matrix = new double[size][size];
    }

    public void setAll(double value) {
        for (int x = 0; x < SIZE; ++x) {
            for (int y = 0; y < SIZE; ++y) {
                Matrix[x][y] = value;
            }
        }
    }

    public void applyConfig(double[][] config) {
        for(int x = 0; x < SIZE; ++x) {
            for(int y = 0; y < SIZE; ++y) {
                Matrix[x][y] = config[x][y];
            }
        }
    }

    public static Bitmap computeConvolution3x3(Bitmap src, ConvolutionMatrix matrix) {
        int width = src.getWidth();
        int height = src.getHeight();
        Bitmap result = Bitmap.createBitmap(width, height, src.getConfig());

        int A, R, G, B;
        int sumR, sumG, sumB;
        int[][] pixels = new int[SIZE][SIZE];

        for(int y = 0; y < height - 2; ++y) {
            for(int x = 0; x < width - 2; ++x) {

                // get pixel matrix
                for(int i = 0; i < SIZE; ++i) {
                    for(int j = 0; j < SIZE; ++j) {
                        pixels[i][j] = src.getPixel(x + i, y + j);
                    }
                }

                // get alpha of center pixel
                A = Color.alpha(pixels[1][1]);

                // init color sum
                sumR = sumG = sumB = 0;

                // get sum of RGB on matrix
                for(int i = 0; i < SIZE; ++i) {
                    for(int j = 0; j < SIZE; ++j) {
                        sumR += (Color.red(pixels[i][j]) * matrix.Matrix[i][j]);
                        sumG += (Color.green(pixels[i][j]) * matrix.Matrix[i][j]);
                        sumB += (Color.blue(pixels[i][j]) * matrix.Matrix[i][j]);
                    }
                }

                // get final Red
                R = (int)(sumR / matrix.Factor + matrix.Offset);
                if(R < 0) { R = 0; }
                else if(R > 255) { R = 255; }

                // get final Green
                G = (int)(sumG / matrix.Factor + matrix.Offset);
                if(G < 0) { G = 0; }
                else if(G > 255) { G = 255; }

                // get final Blue
                B = (int)(sumB / matrix.Factor + matrix.Offset);
                if(B < 0) { B = 0; }
                else if(B > 255) { B = 255; }

                // apply new pixel
                result.setPixel(x + 1, y + 1, Color.argb(A, R, G, B));
            }
        }

        // final image
        return result;
    }
}

Then to do Smooth effect然后做平滑效果

public static Bitmap smooth(Bitmap src, double value) {
    ConvolutionMatrix convMatrix = new ConvolutionMatrix(3);
    convMatrix.setAll(1);
    convMatrix.Matrix[1][1] = value;
    convMatrix.Factor = value + 8;
    convMatrix.Offset = 1;
    return ConvolutionMatrix.computeConvolution3x3(src, convMatrix);
}

You can change values and get the smooth effect as you want.您可以根据需要更改值并获得平滑效果。

That tutorial it's found HERE那个教程在这里找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM