博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
彩色照片转换为黑白照片(Color image converted to black and white picture)
阅读量:6259 次
发布时间:2019-06-22

本文共 3394 字,大约阅读时间需要 11 分钟。

This blog will be talking about the color image converted to black and white picture.

The project structure as follow:

The run result:

==========================================================

source code:

==========================================================

/UUUU_Test/src/com/b510/image/clent/Client.java

1 /** 2  *  3  */ 4 package com.b510.image.clent; 5  6 import java.io.File; 7  8 import com.b510.image.common.Common; 9 import com.b510.image.util.ImageUtil;10 11 /**12  * @author Hongten13  * @create 2014-7-1314  * @mail hongtenzone@foxmail.com15  */16 public class Client {17 18     public static void main(String[] args) {19         File input = new File(Common.ORGINAL_IMAGE);20         File out = new File(Common.PROCESSED_IMAGE);21         ImageUtil.changeImge(input, out);22     }23 }

/UUUU_Test/src/com/b510/image/common/Common.java

1 /** 2  *  3  */ 4 package com.b510.image.common; 5  6 /** 7  * @author Hongten 8  * @create 2014-7-13 9  * @mail hongtenzone@foxmail.com10  */11 public class Common {12 13     // Orginal image path14     public static String ORGINAL_IMAGE = "src/com/b510/image/resources/orginal_image.jpg";15     // Processed image path16     public static String PROCESSED_IMAGE = "src/com/b510/image/resources/processed_image.jpg";17 18     public static String PROCESS_SUCCESS = "Processed successfully.....";19     public static String PROCESS_ERROR = "Processing encounters error!";20 }

/UUUU_Test/src/com/b510/image/util/ImageUtil.java

1 /** 2  *  3  */ 4 package com.b510.image.util; 5  6 import java.awt.Image; 7 import java.awt.color.ColorSpace; 8 import java.awt.image.BufferedImage; 9 import java.awt.image.ColorConvertOp;10 import java.io.File;11 import java.io.FileOutputStream;12 import java.io.IOException;13 14 import javax.imageio.ImageIO;15 16 import com.b510.image.common.Common;17 import com.sun.image.codec.jpeg.JPEGCodec;18 import com.sun.image.codec.jpeg.JPEGImageEncoder;19 20 /**21  * @author Hongten22  * @create 2014-7-1323  * @mail hongtenzone@foxmail.com24  */25 public class ImageUtil {26     /**27      * Color image is converted to black and white picture.28      */29     public static void changeImge(File input, File out) {30         try {31             Image image = ImageIO.read(input);32             int srcH = image.getHeight(null);33             int srcW = image.getWidth(null);34             BufferedImage bufferedImage = new BufferedImage(srcW, srcH, BufferedImage.TYPE_3BYTE_BGR);35             bufferedImage.getGraphics().drawImage(image, 0, 0, srcW, srcH, null);36             bufferedImage = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null).filter(bufferedImage, null);37             FileOutputStream fos = new FileOutputStream(out);38             JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos);39             encoder.encode(bufferedImage);40             fos.close();41             System.out.println(Common.PROCESS_SUCCESS);42         } catch (IOException e) {43             e.printStackTrace();44             throw new IllegalStateException(Common.PROCESS_ERROR, e);45         }46     }47 48 }

========================================================

More reading,and english is important.

I'm Hongten

 

大哥哥大姐姐,觉得有用打赏点哦!多多少少没关系,一分也是对我的支持和鼓励。谢谢。 Hongten博客排名在100名以内。粉丝过千。 Hongten出品,必是精品。

E | hongtenzone@foxmail.com  B | 

========================================================

转载地址:http://gcqsa.baihongyu.com/

你可能感兴趣的文章
UML在需求分析阶段的应用
查看>>
JavaScript:JavaScript事件的处理
查看>>
WEB安全测试的类型
查看>>
ES6笔记(7)-- Promise异步编程
查看>>
早睡早起
查看>>
C#软件监控外部程序运行状态
查看>>
几款开源的图形化Redis客户端管理软件推荐
查看>>
数据库设计中常见表结构的设计技巧
查看>>
CVPR论文《100+ Times Faster Weighted Median Filter (WMF)》的实现和解析(附源代码)。...
查看>>
MATLAB模糊逻辑(2)
查看>>
linux 内核模块管理
查看>>
【每日一摩斯】-【序列】-续-RAC and Sequences (853652.1)
查看>>
把一个select查询结果插入到一个表(可选指定字段和值实例)
查看>>
使用windbg抓取崩溃文件和分析的过程
查看>>
ViewHolder模式超简洁写法
查看>>
项目管理学习笔记之三.绩效分析
查看>>
php十行代码将xml转成数组
查看>>
centos 7 执行 groupinstall报错
查看>>
Web开发入门
查看>>
Flex开发小结(1)如何使用AdvancedDataGrid
查看>>