In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "JAVA graying and binary picture method is what", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "JAVA graying and binary picture method is what" it!
Package image; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class ImageDemo {public void binaryImage () throws IOException {File file = new File (System.getProperty ("user.dir") + "/ src/2722425974762424026.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(System.getProperty("user.dir")+"/src/2722425974762424028.jpg"); ImageIO.write(grayImage, "jpg", newFile); } public void grayImage() throws IOException{ File file = new File(System.getProperty("user.dir")+"/src/2722425974762424026.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(System.getProperty("user.dir")+"/src/2722425974762424027.jpg"); ImageIO.write(grayImage, "jpg", newFile); } public static void main(String[] args) throws IOException { ImageDemo demo = new ImageDemo(); demo.binaryImage(); demo.grayImage(); } } 主要就是BufferedImage.TYPE.BYTE.GRAY灰度化,BufferedImage.TYPE.BYTE.BINARY二值化 原图:Grayed out picture:
Image after binarization:
Thank you for your reading, the above is the "JAVA graying and binary picture method is what" the content, after the study of this article, I believe you on the JAVA graying and binary picture method is what this problem has a deeper understanding, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.