User Tools

Site Tools


ascii_art

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
ascii_art [2023/03/25 12:15] – [Step 1. Read your image and print its height and width in pixels] frchrisascii_art [2023/03/25 12:21] – [Step 1. Read your image and print its height and width in pixels] 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 155: Line 149:
 </code> </code>
 ==== Step 2. Load your image’s pixel data into a 2-dimensional array ==== ==== Step 2. Load your image’s pixel data into a 2-dimensional array ====
 +<code Step2.java>
 +import java.awt.image.BufferedImage;
 +import java.io.File;
 +import java.io.IOException;
 +import javax.imageio.ImageIO;
 +
 +public class Step2
 +{
 +  private BufferedImage image;
 +  private String fileName;
 +  public Step2(String fileName)
 +  {
 +    try
 +    {
 +      // the line that reads the image file
 +      this.fileName = fileName;
 +      image = ImageIO.read(new File(fileName));
 +      System.out.println(fileName + " read ");
 +    
 +      System.out.println("Demensions of " + fileName + ": ");
 +      // Print the width and height of the image using a BufferedImage method.  
 +     
 +    } 
 +    catch (IOException e)
 +    {
 +      System.out.println("Whoa... something's not right:\n"+e);
 +    }
 +  }
 +
 +  public static void main(String[] args)
 +  {
 +    new Step2("My_Picture.jpg");
 +  }
 +
 +}
 +</code>
 ==== 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

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki