开发遇到的问题

简介: 开发遇到的问题

1.保证handler处理的是最新的消息

if (!handler.getLooper().getQueue().isIdle()) {
      handler.removeMessages(0);
}
 handler.sendEmptyMessageDelayed(0,2000);

2.属性动画实现View背景色渐变动画

ValueAnimator animator = ObjectAnimator.ofInt(mNavigationRoot, "backgroundColor", 0x00ff0000, 0x6600ff00);//对背景色颜色进行改变,操作的属性为"backgroundColor",此处必须这样写,不能全小写,后面的颜色为在对应颜色间进行渐变
            animator.setDuration(3000);
            animator.setEvaluator(new ArgbEvaluator());//如果要颜色渐变必须要ArgbEvaluator,来实现颜色之间的平滑变化,否则会出现颜色不规则跳动
            animator.start();

3.bitmap模糊化

/**
     * 传递bitmap 传递模糊半径 返回一个被模糊的bitmap
     * 比较耗时
     * @param sentBitmap
     * @param radius
     * @return
     */
    public Bitmap createBlurBitmap(Bitmap sentBitmap, int radius) {
        Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
        if (radius < 1) {
            return (null);
        }
        int w = bitmap.getWidth();
        int h = bitmap.getHeight();
        int[] pix = new int[w * h];
        bitmap.getPixels(pix, 0, w, 0, 0, w, h);
        int wm = w - 1;
        int hm = h - 1;
        int wh = w * h;
        int div = radius + radius + 1;
        int r[] = new int[wh];
        int g[] = new int[wh];
        int b[] = new int[wh];
        int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
        int vmin[] = new int[Math.max(w, h)];
        int divsum = (div + 1) >> 1;
        divsum *= divsum;
        int dv[] = new int[256 * divsum];
        for (i = 0; i < 256 * divsum; i++) {
            dv[i] = (i / divsum);
        }
        yw = yi = 0;
        int[][] stack = new int[div][3];
        int stackpointer;
        int stackstart;
        int[] sir;
        int rbs;
        int r1 = radius + 1;
        int routsum, goutsum, boutsum;
        int rinsum, ginsum, binsum;
        for (y = 0; y < h; y++) {
            rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
            for (i = -radius; i <= radius; i++) {
                p = pix[yi + Math.min(wm, Math.max(i, 0))];
                sir = stack[i + radius];
                sir[0] = (p & 0xff0000) >> 16;
                sir[1] = (p & 0x00ff00) >> 8;
                sir[2] = (p & 0x0000ff);
                rbs = r1 - Math.abs(i);
                rsum += sir[0] * rbs;
                gsum += sir[1] * rbs;
                bsum += sir[2] * rbs;
                if (i > 0) {
                    rinsum += sir[0];
                    ginsum += sir[1];
                    binsum += sir[2];
                } else {
                    routsum += sir[0];
                    goutsum += sir[1];
                    boutsum += sir[2];
                }
            }
            stackpointer = radius;
            for (x = 0; x < w; x++) {
                r[yi] = dv[rsum];
                g[yi] = dv[gsum];
                b[yi] = dv[bsum];
                rsum -= routsum;
                gsum -= goutsum;
                bsum -= boutsum;
                stackstart = stackpointer - radius + div;
                sir = stack[stackstart % div];
                routsum -= sir[0];
                goutsum -= sir[1];
                boutsum -= sir[2];
                if (y == 0) {
                    vmin[x] = Math.min(x + radius + 1, wm);
                }
                p = pix[yw + vmin[x]];
                sir[0] = (p & 0xff0000) >> 16;
                sir[1] = (p & 0x00ff00) >> 8;
                sir[2] = (p & 0x0000ff);
                rinsum += sir[0];
                ginsum += sir[1];
                binsum += sir[2];
                rsum += rinsum;
                gsum += ginsum;
                bsum += binsum;
                stackpointer = (stackpointer + 1) % div;
                sir = stack[(stackpointer) % div];
                routsum += sir[0];
                goutsum += sir[1];
                boutsum += sir[2];
                rinsum -= sir[0];
                ginsum -= sir[1];
                binsum -= sir[2];
                yi++;
            }
            yw += w;
        }
        for (x = 0; x < w; x++) {
            rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
            yp = -radius * w;
            for (i = -radius; i <= radius; i++) {
                yi = Math.max(0, yp) + x;
                sir = stack[i + radius];
                sir[0] = r[yi];
                sir[1] = g[yi];
                sir[2] = b[yi];
                rbs = r1 - Math.abs(i);
                rsum += r[yi] * rbs;
                gsum += g[yi] * rbs;
                bsum += b[yi] * rbs;
                if (i > 0) {
                    rinsum += sir[0];
                    ginsum += sir[1];
                    binsum += sir[2];
                } else {
                    routsum += sir[0];
                    goutsum += sir[1];
                    boutsum += sir[2];
                }
                if (i < hm) {
                    yp += w;
                }
            }
            yi = x;
            stackpointer = radius;
            for (y = 0; y < h; y++) {
                pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16)
                        | (dv[gsum] << 8) | dv[bsum];
                rsum -= routsum;
                gsum -= goutsum;
                bsum -= boutsum;
                stackstart = stackpointer - radius + div;
                sir = stack[stackstart % div];
                routsum -= sir[0];
                goutsum -= sir[1];
                boutsum -= sir[2];
                if (x == 0) {
                    vmin[y] = Math.min(y + r1, hm) * w;
                }
                p = x + vmin[y];
                sir[0] = r[p];
                sir[1] = g[p];
                sir[2] = b[p];
                rinsum += sir[0];
                ginsum += sir[1];
                binsum += sir[2];
                rsum += rinsum;
                gsum += ginsum;
                bsum += binsum;
                stackpointer = (stackpointer + 1) % div;
                sir = stack[stackpointer];
                routsum += sir[0];
                goutsum += sir[1];
                boutsum += sir[2];
                rinsum -= sir[0];
                ginsum -= sir[1];
                binsum -= sir[2];
                yi += w;
            }
        }
        bitmap.setPixels(pix, 0, w, 0, 0, w, h);
        return bitmap;
    }
目录
相关文章
|
6月前
|
缓存 负载均衡 安全
开发领域
开发领域
50 4
|
5月前
|
IDE 前端开发 JavaScript
蓝河BlueO - 快速开始开发
蓝河BlueO - 快速开始开发
54 0
|
运维 监控 Kubernetes
如何开发ChatOps
如何开发ChatOps
如何开发ChatOps
|
存储 Dubbo 前端开发
开发之所以然
想点啥说点啥
|
移动开发 开发框架 小程序
小程序开发之框架篇
本篇文章会从跨端框架的角度入手,带你了解如何选择小程序开发框架,并介绍我们的最佳实践
|
小程序 IDE Serverless
开发前准备
在开始使用阿里云小程序Serverless服务开发支付宝小程序前,您需要确保完成以下准备工作。
开发前准备
|
测试技术
开发流程模型
开发流程模型
999 0
|
Java 测试技术 开发工具
如何自己开发软件测试工具
一说到自动化测试工具,大家很多人都会想到的是QTP、LR或者selenium之类的工具,要大家一开始设计一个这样的工具,其实确实很有难度,因为其包含的功能细节太过庞大。当年的我,开始设计开发工具的过程中,走了很多弯路,例如:做工具的界面技术的历程,刚开始用tcl/tk脚本语言,用tcl写底层框架,用tk写图形界面,后来发现tk虽然构造图形方便,但可拓展性实在太差。
2042 0
|
程序员
常人对开发的误解
步入职场,对比刚毕业时的那段创业时间,觉得自己有一些做的不对的地方,或者整个创业团队导致失败的地方。 失败原因很多,天时、地利、人和都有因素,这次只想说说关于大家对开发的误解,这也是失败的原因之一。