zoukankan      html  css  js  c++  java
  • 钢镚儿冲刺一周期第一天

    一、说在前面

      今天的目标是实现使用java完成对图片像素点的操作进而实现图片的褪色处理,作为之后梦想清单的原型;

    二、大体思路

      由于有一点PS的基础,所以明白褪色相应的算法原理,根据RGB的数量对颜色进行判断进而通过代码遍历图片的每个像素点并更形成相应的黑白色。并且Android和java的关系非常近,使用java写出来之后那迁移到Android会简单很多。

    三、代码

    import java.awt.image.BufferedImage;  
    import java.io.File;  
    import java.io.IOException;
    import java.net.URLDecoder;
    
    import javax.imageio.ImageIO;  
    public class Image   
    {  
        private static String basePath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
        public void binaryImage() throws IOException  
        {  
            
            File file = new File("C:\Users\26218\Desktop\c.jpg");  
            BufferedImage image = ImageIO.read(file);  
            int width = image.getWidth();  
            int height = image.getHeight();   
            BufferedImage grayImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);  
            for(int i= 0 ; i < width ; i++)  
            {  
                for(int j = 0 ; j < height; j++)  
                {  
                    int rgb = image.getRGB(i, j);  
                    grayImage.setRGB(i, j, rgb);  
                }  
            }     
            File newFile = new File("d.jpg");  
            ImageIO.write(grayImage, "jpg", newFile);  
        }  
        public void grayImage() throws IOException  
        {  
            File file = new File("c.jpg");  
            BufferedImage image = ImageIO.read(file);     
            int width = image.getWidth();  
            int height = image.getHeight();   
            BufferedImage grayImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);  
            for(int i= 0 ; i < width ; i++)  
            {  
                for(int j = 0 ; j < height; j++)  
                {  
                    int rgb = image.getRGB(i, j);  
                    grayImage.setRGB(i, j, rgb);  
                }  
            }  
            File newFile = new File("e.jpg");  
            ImageIO.write(grayImage, "jpg", newFile);  
        }  
        public static void main(String[] args) throws IOException   
        {  
            Image demo = new Image();  
            basePath=URLDecoder.decode(basePath,"utf-8");
            demo.binaryImage();  
            demo.grayImage();  
        }  
    }  
  • 相关阅读:
    数据库设计准则(第一、第二、第三范式说明)
    Linux之chmod使用
    数据备份——PHP
    PHP语言性能优化——少使用魔术方法
    PHP性能之语言性能优化:安装VLD扩展——检测性能
    PHP性能之语言性能优化:安装VLD扩展——检测性能
    PHP性能之语言性能优化:安装VLD扩展——检测性能
    socket、fsockopen、curl、stream 区别
    iOS 下 Podfile 使用方法
    使用 NVM 管理不同的 Node.js 版本
  • 原文地址:https://www.cnblogs.com/suanai/p/12753569.html
Copyright © 2011-2022 走看看