In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how java uses characters to draw a SpongeBob. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
Draw a SpongeBob with characters
Draw a SpongeBob with the characters "" and "*". The effect is as follows:
Emm... The effect may not be very good, the original picture looks like this:
Here's my code.
Code
Tip: the code is for reference only, mostly from the network
Package package1;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO;public class ImageDraw {public static void main (String [] args) throws IOException {/ / remove the comment "/ /" from that line which graying method you need to use. / / grayImage (1, "E:\\ image.jpg"); / / maximum method ashing / / grayImage (2, "E:\\ image.jpg"); / / minimum method ashing / / grayImage (3, "E:\\ image.jpg"); / / average method ashing / / grayImage (4, "E:\\ image.jpg") / / weighted gray} public static void grayImage (int status, String imagePath) throws IOException {File file = new File (imagePath); BufferedImage image = ImageIO.read (file); int width = image.getWidth (); int height = image.getHeight (); BufferedImage grayImage = new BufferedImage (width, height, image.getType ()); for (int I = 0; I
< height; i++) { for (int j = 0; j < width; j++) { int color = image.getRGB(j, i); final int r = (color >> 16) & 0xff; final int g = (color > > 8) & 0xff; final int b = color & 0xff; int gray = 0; if (status = = 1) {gray = getBigger (r, g, b) / / maximum method ashing} else if (status = = 2) {gray = getSmall (r, g, b); / / minimum method ashing} else if (status = = 3) {gray = getAvg (r, g, b) / / mean method gray} else if (status = = 4) {gray= (int) (0.3 * r + 0.59g + 0.11b); / / weighted gray} if (gray= y & x > = z) {return x } else if (y > = x & & y > = z) {return y;} else if (z > = x & & z > = y) {return z;} else {return 0 }} / / compare the size of the three numbers to the minimum number public static int getSmall (int x, int y, int z) {if (x = z) {return y;} else if (z > = x & & z > = y) {return z;} else {return 0 }} / / mean public static int getAvg (int x, int y, int z) {int avg = (x + y + z) / 3; return avg;}} after reading the above, do you have any further understanding of how java uses characters to draw a SpongeBob? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.