Get the App
SLTechnology News&Howtos  ›  Development  › 

Java how to use characters to draw a SpongeBob

Shulou Source: shulou.com Published: 2022-06-02 02:51:30 10月15日 Update

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.

Tags: Grayscale baby sponge character minimum code content maximum mean effect maximum for reference only one line two number original image size most average way Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia OPPO Reno Shulou Technology Shulou Information vpn