zoukankan      html  css  js  c++  java
  • 团队博客

    图片编辑

    public static Bitmap handleImageEffect(Bitmap bm,float hue,float saturation,float lum){
            Bitmap bmp=Bitmap.createBitmap(bm.getWidth(),bm.getHeight(),Bitmap.Config.ARGB_8888);
            Canvas canvas=new Canvas(bmp);
            Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);
     
            ColorMatrix hueMatrix=new ColorMatrix();
            hueMatrix.setRotate(0,hue);
            hueMatrix.setRotate(1,hue);
            hueMatrix.setRotate(2,hue);
     
            ColorMatrix  saturationMatrix=new ColorMatrix();
            saturationMatrix.setSaturation(saturation);
     
            ColorMatrix lumMatrix=new ColorMatrix();
            lumMatrix.setScale(lum,lum,lum,1);
     
            ColorMatrix imageMatrix=new ColorMatrix();
            imageMatrix.postConcat(hueMatrix);
            imageMatrix.postConcat(saturationMatrix);
            imageMatrix.postConcat(lumMatrix);
     
            paint.setColorFilter(new ColorMatrixColorFilter(imageMatrix));
            canvas.drawBitmap(bm,0,0,paint);
     
            return bmp;
        }
    public static Bitmap handleImageNegative(Bitmap bm){
            int width=bm.getWidth();
            int height=bm.getHeight();
            int color;
            int r,g,b,a;
     
            Bitmap bmp=Bitmap.createBitmap(width,height,
                    Bitmap.Config.ARGB_8888);
     
            int[] oldPic=new int[width*height];
            int[] newPic=new int[width*height];
            bm.getPixels(oldPic,0,width,0,0,width,height);
            for (int i=0;i<width*height;i++){
                color=oldPic[i];
                r= Color.red(color);
                g=Color.green(color);
                b=Color.blue(color);
                a=Color.alpha(color);
                r=255-r;
                g=255-g;
                b=255-b;
                if(r>255){
                    r=255;
                }else if(r<0){
                    r=0;
                }
     
                if(g>255){
                    g=255;
                }else if(g<0){
                    g=0;
                }
     
                if(b>255){
                    b=255;
                }else if(b<0){
                    b=0;
                }
     
                newPic[i]=Color.argb(a,r,g,b);
            }
            bmp.setPixels(newPic,0,width,0,0,width,height);
            return bmp;
        }
     
        public static  Bitmap handleImagePixelsOldPhoto(Bitmap bm){
            Bitmap bmp=Bitmap.createBitmap(bm.getWidth(),
                    bm.getHeight(),Bitmap.Config.ARGB_8888);
            int width=bm.getWidth();
            int height=bm.getHeight();
            int color=0;
            int r,g,b,a,r1,g1,b1;
             int[] oldPic=new int[width*height];
             int[] newPic=new int[width*height];
             bm.getPixels(oldPic,0,width,0,0,width,height);
             for(int i=0;i<width*height;i++){
                 color=oldPic[i];
                 r= Color.red(color);
                 g=Color.green(color);
                 b=Color.blue(color);
                 a=Color.alpha(color);
                 r1=(int)(0.393*r+0.769*g+0.189*b);
                 g1=(int)(0.349*r+0.686*g+0.168*b);
                b1=(int)(0.272*r+0.534*g+0.131*b);
                if(r1>255){
                    r1=255;
                }if(g1>255){
                    g1=255;
                 }if(b1>255){
                    b1=255;
                 }
                 newPic[i]= Color.argb(a,r1,g1,b1);
             }
             bmp.setPixels(newPic,0,width,0,0,width,height);
             return bmp;
        }
     
        public  static  Bitmap handleImageRelief(Bitmap bm){
            Bitmap bmp=Bitmap.createBitmap(bm.getWidth(),bm.getHeight(),
                    Bitmap.Config.ARGB_8888);
            int width=bm.getWidth();
            int height=bm.getHeight();
            int color=0,colorBefore=0;
            int a,r,g,b,r1,g1,b1;
            int[] oldPic=new int[width*height];
            int[] newPic=new int[width* height];
            bm.getPixels(oldPic,0,width,0,0,width,height);
            for(int i=1;i<width*height;i++){
                colorBefore=oldPic[i-1];
                a=Color.alpha(colorBefore);
                r=Color.red(colorBefore);
                g=Color.green(colorBefore);
                b=Color.blue(colorBefore);
     
                color=oldPic[i];
                r1=Color.red(color);
                g1=Color.green(color);
                b1=Color.blue(color);
                 r=(r-r1+127);
                 g=(g-g1+127);
                 b=(b-b1+127);
                 if(r>255){
                     r=255;
                 }if(g>255){
                     g=255;
                }if(b>255){
                     b=255;
                }
                newPic[i]=Color.argb(a,r,g,b);
            }
            bmp.setPixels(newPic,0,width,
                    0,0,width,height);
            return bmp;
        }
     
    }

    问题:还是老问题,单独可运行,和其他代码和一起时不行。

  • 相关阅读:
    重新拾起写博客
    此博客正式停用。。
    合并两个git项目,并保留源仓库的所有提交记录
    红米note3Toast不显示问题
    Android8.0[Only fullscreen opaque activities can request orientation]问题解决
    (转)Git代理配置全记录包含http和ssh两种协议的情况
    (转)intent-filter 之 data 「scheme, host, port, mimeType, path, pathPrefix, pathPattern」
    (转)android mimeType表
    罗伯特议事规则
    (转)Android之shape与selector实现圆角
  • 原文地址:https://www.cnblogs.com/hfy717/p/14904870.html
Copyright © 2011-2022 走看看