吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1691|回复: 15
收起左侧

[其他转载] android 及html 首页变灰

  [复制链接]
djwdj 发表于 2022-12-3 17:03
android 的java 及kt 首页变灰,RenderScript 将图片处理为黑白
html的css及js首页变灰
沉痛悼念伟人逝世!

先上html 的css
<style type="text/css">
        html{-webkit-filter:grayscale(100%);filter:grayscale(100%);}
        body{background-blend-mode:luminosity;}
</style>

ie8的css(360的方案)
<style type="text/css">
html {
    filter: grayscale(100%);
    -webkit-filter: grayscale(100%);
    -ms-filter: grayscale(100%);
    -o-filter: grayscale(100%);
    filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)
}

img {
    -webkit-filter: grayscale(100%);
    -moz-filter: grayscale(100%);
    -ms-filter: grayscale(100%);
    -o-filter: grayscale(100%);
    filter: grayscale(100%);
    filter: url(https://s5.ssl.qhres2.com/static/916198b3e87868a3.svg#grayscale);
    filter: gray
}
</style>

svg的内容

<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
    <filter id="grayscale">
        <feColorMatrix type="matrix" values="0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0"/>
    </filter>
</svg>

JS
<script>
document.body.style.WebkitFilter = "grayscale(100%)"; // Chrome, Safari, and Opera
document.body.style.filter = "grayscale(100%)";
</script>


Android
java
    public static void BianHui(View v){
        Paint paint = new Paint();
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0f);
        paint.setColorFilter(new ColorMatrixColorFilter(cm));
        v.setLayerType(View.LAYER_TYPE_HARDWARE, paint);
    }

例:全局调用

BianHui(getWindow().getDecorView());

kt:
val paint = Paint()
val cm = ColorMatrix()
cm.setSaturation(0f)
paint.colorFilter = ColorMatrixColorFilter(cm)
window.decorView.setLayerType(View.LAYER_TYPE_HARDWARE, paint)


RenderScript处理图片(太久没有,忘了,搬大佬
木质的旋律@简书

一、什么是 RenderScript ?
RenderScript 是 Android 自带一个高效的计算框架,能够自动利用 CPU、GPU、DSP 来做并行计算,能在处理图片、数学模型计算等场景提供高效的计算能力。
语法类似 C/C++, 但它是在运行时编译,是跨平台的。性能比 Java 好,比 Native 略差。

二、如何使用 RenderScript ?
使用时分两个步骤:
(1) 编写 .rs 脚本文件;
(2) 使用编写的文件;

(1) 编写 .rs 文件
这里我们用一个很简单的 将图片置灰 为例实现 Gray.rs 文件;

#pragma version(1)
#pragma rs java_package_name(me.moolv.demo.rs)

void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
    // a 是透明度,这里不修改透明度。
    out->a = in->a;

    // 快,但并不是真正意义的去色
    out->r = out->g = out->b = (in->r + in->g + in->b) / 3;

    // 慢,但是是真正的去色
    // out->r = out->g = out->b = (in->r * 299 + in->g * 587 + in->b * 114 + 500) / 1000;
}

void init() {
}

第1行声明 RenderScript 的版本;
第2行 java_package_name 生命该脚本所在的Java包的包名;

root 函数:
root 函数是这个脚本的入口函数,对于图片来说,root函数负责对每一个像素做处理。
参数 in 是输入像素点的指针; out 是输出像素点的指针。

init 函数:
init 函数是可选的,用于做初始化的工作。

(2) 在 Java 代码中使用
在 Java 代码中 import:

import me.moolv.demo.rs.ScriptC_Gray;

这里的类名是 ScriptC_ 加上 .rs 的文件名。包名就是在 rs 文件生声明的包名。

下面是具体使用:


/** 
 * 将 bitmap 去色后返回一张新的 Bitmap。
 */
public static Bitmap gray(@NonNull Context context, @NonNull Bitmap bitmap) {

    // 创建输出 bitamp
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap outBitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);

    // 创建 RenderScript 对象
    RenderScript rs = RenderScript.create(context);

    // 创建输入、输出 Allocation
    Allocation allIn  = Allocation.createFromBitmap(rs, bitmap);
    Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);

    // 创建我们在上面定义的 script
    ScriptC_Gray script = new ScriptC_Gray(rs);

    // 对每一个像素执行 root 方法
    script.forEach_root(allIn, allOut);

    // 将执行结果复制到输出 bitmap 上
    allOut.copyTo(outBitmap);

    // 释放资源
    rs.destroy();
    return outBitmap;
}

三、多个 kernal 函数
除了 root 函数,我们还可以在 .rs 中定义其他的 kernal 函数,例如:

/** 
 * 黑金色转换
 */
uchar4 __attribute__((kernel)) blackGold(uchar4 in, uint32_t x, uint32_t y) {
    uchar4 out = in;

    if ((in.r < in.b) && (in.g < in.b)) {
        out.r = out.g = out.b = (in.r*299 + in.g*587 + in.b*114 + 500) / 1000;
    }

    return out;
}

其中函数返回值必须是 uchar4, 并且用 attribute((kernel)) 标记该函数是个 kernal 函数。

在 Java 代码中这样调用就可以了:

script.forEach_blackGold(allIn, allOut);

免费评分

参与人数 4吾爱币 +4 热心值 +3 收起 理由
hwh425 + 1 我很赞同!
yyb414 + 1 + 1 热心回复!
殘心 + 1 + 1 热心回复!
Tonyha7 + 1 + 1 用心讨论,共获提升!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

kover 发表于 2022-12-3 21:46
现在恢复彩色才是主流
lfordch 发表于 2022-12-3 21:27
aonima 发表于 2022-12-3 17:36
夏520 发表于 2022-12-3 17:48
感谢分享
wyd521 发表于 2022-12-3 18:59
感谢楼主分享
advancejar 发表于 2022-12-3 20:09
tampermonkey有个专门的 脚本,叫啥天堂的
OrientalGlass 发表于 2022-12-3 21:03
感谢分享,原理原来不是很复杂
yzjtxwd 发表于 2022-12-3 22:32
学习一下
runfog 发表于 2022-12-4 16:03
最近几天,网页首页变灰,app将图片处理为黑白
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-27 07:39

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表