利用java怎么实现一个将图片去色的功能-创新互联

本篇文章为大家展示了利用java怎么实现一个将图片去色的功能,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

专注于为中小企业提供成都网站设计、做网站服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业晋江免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上1000+企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

现在我们要将这样的一张图片

变成为

利用java怎么实现一个将图片去色的功能

代码

package com.epoint.wdg.test; 
 
import java.awt.Color; 
import java.awt.image.BufferedImage; 
import java.io.File; 
import java.io.IOException; 
 
import javax.imageio.ImageIO; 
 
public class ImgTest { 
  public static void main(String[] args) throws IOException { 
    File file=new File("C://Users/wdg/Desktop/people.png"); 
    //showParamterofImg(file); 
    File file2=changeImgtoGray(file); 
    grayPicToBW(file2); 
  } 
  public static void getRGB(File file) throws IOException{ 
    int []rgb =new int[3]; 
    BufferedImage img=ImageIO.read(file); 
    int pixel=img.getRGB(2, 3); 
    // 下面三行代码将一个数字转换为RGB数字  
    rgb[0] = (pixel & 0xff0000) >> 16;  
    rgb[1] = (pixel & 0xff00) >> 8;  
    rgb[2] = (pixel & 0xff);  
    System.out.println(rgb[0]+"-"+rgb[1]+"-"+rgb[2]); 
     
  } 
  //把图片变灰色 
  public static File changeImgtoGray(File file) throws IOException{ 
    float []rgb =new float[3]; 
    BufferedImage img=ImageIO.read(file); 
    //现在我需要获取到没一点的rgb 
    int y=img.getHeight(); 
    int x=img.getWidth(); 
    BufferedImage grayImage = new BufferedImage(x, y, BufferedImage.TYPE_BYTE_GRAY); 
    for(int i=0;i> 16;  
         rgb[1] = (pixel & 0xff00) >> 8;  
         rgb[2] = (pixel & 0xff);  
        int gray=(int) (rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11); 
         Color color=new Color(gray,gray,gray); 
         img.setRGB(i, j, color.getRGB()); 
 
      } 
    } 
    File newFile = new File("C://Users/wdg/Desktop/"+"/method5.jpg");  
    ImageIO.write(img, "jpg", newFile);  
    // grayPicToBW(newFile); 
    return newFile; 
  } 

网页名称:利用java怎么实现一个将图片去色的功能-创新互联
文章URL:http://myzitong.com/article/diphep.html