彩色照片转换为黑白照片(Color image converted to black and white picture)
2014-07-13 02:34
525 查看
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
/UUUU_Test/src/com/b510/image/common/Common.java
/UUUU_Test/src/com/b510/image/util/ImageUtil.java
========================================================
More reading,and english is important.
I'm Hongten
========================================================
The project structure as follow:
The run result:
==========================================================
source code:
==========================================================
/UUUU_Test/src/com/b510/image/clent/Client.java
/** * */ package com.b510.image.clent; import java.io.File; import com.b510.image.common.Common; import com.b510.image.util.ImageUtil; /** * @author Hongten * @create 2014-7-13 * @mail hongtenzone@foxmail.com */ public class Client { public static void main(String[] args) { File input = new File(Common.ORGINAL_IMAGE); File out = new File(Common.PROCESSED_IMAGE); ImageUtil.changeImge(input, out); } }
/UUUU_Test/src/com/b510/image/common/Common.java
/** * */ package com.b510.image.common; /** * @author Hongten * @create 2014-7-13 * @mail hongtenzone@foxmail.com */ public class Common { // Orginal image path public static String ORGINAL_IMAGE = "src/com/b510/image/resources/orginal_image.jpg"; // Processed image path public static String PROCESSED_IMAGE = "src/com/b510/image/resources/processed_image.jpg"; public static String PROCESS_SUCCESS = "Processed successfully....."; public static String PROCESS_ERROR = "Processing encounters error!"; }
/UUUU_Test/src/com/b510/image/util/ImageUtil.java
/** * */ package com.b510.image.util; import java.awt.Image; import java.awt.color.ColorSpace; import java.awt.image.BufferedImage; import java.awt.image.ColorConvertOp; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import javax.imageio.ImageIO; import com.b510.image.common.Common; import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.jpeg.JPEGImageEncoder; /** * @author Hongten * @create 2014-7-13 * @mail hongtenzone@foxmail.com */ public class ImageUtil { /** * Color image is converted to black and white picture. */ public static void changeImge(File input, File out) { try { Image image = ImageIO.read(input); int srcH = image.getHeight(null); int srcW = image.getWidth(null); BufferedImage bufferedImage = new BufferedImage(srcW, srcH, BufferedImage.TYPE_3BYTE_BGR); bufferedImage.getGraphics().drawImage(image, 0, 0, srcW, srcH, null); bufferedImage = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null).filter(bufferedImage, null); FileOutputStream fos = new FileOutputStream(out); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos); encoder.encode(bufferedImage); fos.close(); System.out.println(Common.PROCESS_SUCCESS); } catch (IOException e) { e.printStackTrace(); throw new IllegalStateException(Common.PROCESS_ERROR, e); } } }
========================================================
More reading,and english is important.
I'm Hongten
========================================================
相关文章推荐
- How to Display Image In Picturebox in VC++ from Iplimage and Mat
- 论文笔记之:Let there be Color!: Joint End-to-end Learning of Global and Local Image Priors for Automatic
- How to Display Image In Picturebox in VC++ from Iplimage and Mat
- How to resolve Android Camera Preview on Emulator show white and black square only?
- H5将彩色照片转换成黑白照片
- Let there be Color!: Joint End-to-end Learning of Global and Local Image Priors for Automatic Image
- set transparent button image and background color to button
- 论文笔记之:Let there be Color!: Joint End-to-end Learning of Global and Local Image Priors for Automatic
- Android to the picture plus text and image watermarking example code
- 动态将彩色图片动画过渡到黑白图片的BlackAndWhiteView
- How to resolve Android Camera Preview on Emulator show white and black square only?
- Let there be Color!: Joint End-to-end Learning of Global and Local Image Priors for Automatic Image
- Flex3学习轨迹:将彩色照片转换成黑白照片
- Vision with Direction: A Systematic Introduction to Image Processing and Computer Vision
- Volume Rendering using CUDA – Trilinear Interp. and Image Color-Map
- How to deal with Whitespaces in scanf, gets(in C) and cin, getline(in C++) ?
- Modify a prepackaged image and Use YUM to install software
- Saving Workbooks to PDF and XPS Formats in Excel 2007 (C#.net word excel powerpoint (ppt) 转换成 pdf 文件)
- image to DataBase and show the image
- Rendering ink and image to a bitmap using WPF