zoukankan      html  css  js  c++  java
  • 图片处理熔铸特效

    1、算法

    r = r*128/(g+b +1);
    g = g*128/(r+b +1);
    b = b*128/(g+r +1);
    2、代码实现

    public Bitmap render(Bitmap bitmap)
      {
        if(bitmap == null)return null;
    
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
    
        int[] pixels = new int[width * height];
        bitmap.getPixels(pixels ,0 , width , 0 , 0 , width , height);
        for(int i=0 ; i<height ; i++)
        {
          for(int j=0 ; j<width ; j++)
          {
            int pixel = pixels[i*width +j];
            int r = (pixel & 0x00ff0000)>>16;
            int g = (pixel & 0x0000ff00)>>8;
            int b = (pixel & 0x000000ff);
    
            r = r*128/(g+b +1);
            r = colorSafe(r);
    
            g = g*128/(r+b +1);
            g = colorSafe(g);
    
            b = b*128/(g+r +1);
            b = colorSafe(b);
            pixels[i*width +j] = (pixel & 0xff000000) + (r<<16)+ (g<<8) +b;
          }
        }
    
        return Bitmap.createBitmap(pixels ,width , height , Config.ARGB_8888);
      }
    
    public int colorSafe(int value)
    {
    
      if(value<0)
      {
        value = 0;
      }
    
      if(value>255)
      {
        value = 255;
      }
      return value;
    }
  • 相关阅读:
    C++(四)--线程与进程
    http1.0升级到http1.1
    odoo 基础
    Ubuntu 上安装配置 Ldap
    odoo 怎样使代码生效
    Odoo 创建自定义模块
    开源的软件应用
    域控
    Flask 数据库 SQLAlchemy
    CentOS 8 防火墙 firewall 相关命令
  • 原文地址:https://www.cnblogs.com/lipeil/p/2696879.html
Copyright © 2011-2022 走看看