ascii_art
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
ascii_art [2023/03/25 12:20] – [Step 2. Load your image’s pixel data into a 2-dimensional array] frchris | ascii_art [2023/03/25 14:21] – [Step 2. Load your image’s pixel data into a 2-dimensional array] frchris | ||
---|---|---|---|
Line 117: | Line 117: | ||
import java.io.IOException; | import java.io.IOException; | ||
import javax.imageio.ImageIO; | import javax.imageio.ImageIO; | ||
- | import java.awt.*; | ||
- | import java.awt.geom.AffineTransform; | ||
- | import javax.swing.JFrame; | ||
- | import javax.swing.JPanel; | ||
- | import javax.swing.JLabel; | ||
- | import javax.swing.ImageIcon; | ||
public class Step1 | public class Step1 | ||
Line 132: | Line 126: | ||
try | try | ||
{ | { | ||
- | // the line that reads the image file | ||
this.fileName = fileName; | this.fileName = fileName; | ||
image = ImageIO.read(new File(fileName)); | image = ImageIO.read(new File(fileName)); | ||
Line 165: | Line 158: | ||
private BufferedImage image; | private BufferedImage image; | ||
private String fileName; | private String fileName; | ||
+ | private int width, | ||
+ | private int[] rgb; // for 8bit RGB packed in an int array | ||
+ | private Color[][] px; | ||
public Step2(String fileName) | public Step2(String fileName) | ||
{ | { | ||
Line 173: | Line 169: | ||
image = ImageIO.read(new File(fileName)); | image = ImageIO.read(new File(fileName)); | ||
System.out.println(fileName + " read "); | System.out.println(fileName + " read "); | ||
- | | + | width = image.getWidth(); |
- | System.out.println(" | + | height = image.getHeight(); |
- | // Print the width and height | + | System.out.println(" |
+ | rgb = image.getRGB(0, | ||
+ | System.out.println(rgb.length); | ||
+ | // rgb is a 1D array, with the rows listed one after the other. | ||
+ | ///to convert to a 2D array use something like this: | ||
+ | // grid (x,y) = rgb[ y*width + x]; | ||
+ | // Make a new 2D array of color name px, and fill it from the | ||
+ | // for example, px[0][0] = new Color ( rgb[0] ); | ||
+ | | ||
} | } | ||
Line 183: | Line 187: | ||
} | } | ||
} | } | ||
+ | public Color[][] getPx() { return px;} | ||
public static void main(String[] args) | public static void main(String[] args) | ||
{ | { | ||
Line 191: | Line 195: | ||
} | } | ||
</ | </ | ||
+ | You can see what your new 2D Array of Color looks like with {{ :: | ||
+ | |||
==== Step 3. Convert the RGB tuples of your pixels into single brightness numbers | ==== Step 3. Convert the RGB tuples of your pixels into single brightness numbers | ||
==== Step 4. Convert brightness numbers to ASCII characters | ==== Step 4. Convert brightness numbers to ASCII characters |
ascii_art.txt · Last modified: 2023/03/27 10:46 by frchris