zoukankan      html  css  js  c++  java
  • 图片处理连环画特效

    1、算法

    R = |g – b + g + r| * r / 256

    G = |b – g + b + r| * r / 256;

    B = |b – g + b + r| * g / 256;

    然后灰化。

    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 = algorithm(g , b , r , r);
            g = algorithm(b , g , r , r);
            b = algorithm(b , g , r , g);
    
            int gray = (r*3+g*6+b)/10;
            pixels[i*width +j] = (pixel & 0xff000000) + (gray<<16)+ (gray<<8) +gray;
          }
        }
    
        return Bitmap.createBitmap(pixels ,width , height , Config.ARGB_8888);
      }
    public int algorithm(int doubleValue , int negative , int positive , int multi) { int value = 2*doubleValue - negative +positive; if(value<0) { value = -value; } value = value * multi /256; if(value>255) { value = 255; } return value; }
  • 相关阅读:
    Centos 7 KVM安装win10
    python3.6小程序
    linux随手笔记(Centos为主)
    python 3.6练习题(仿购物车)
    linux mint软件安装
    pacman详解及常见问题
    manjaro安装及设置
    Ansible安装及配置
    大盘分时黄白线
    渊海子平学习
  • 原文地址:https://www.cnblogs.com/lipeil/p/2696591.html
Copyright © 2011-2022 走看看