java.lang.ObjectPict
public class Pict
This utility class contains static methods to translate between images and 2-D arrays.
To convert a image's filename or URL to an array of int:
int[][] myPixels = imageToPixelsBW( "http://www.radford.edu/~itec120/2007fall-ibarland/Lectures/lect01-ufo/muse.jpeg" );
You can then modify that array as you please, to do image processing.
Then, to draw a 2-D array of int as a black-and-white picture:
displayAsImage( myPixels );
Note that once you have displayed an image, modifying the array won't
retroactively change that image; you'll have to call displayAsImage again
after making any modifications to see a new image.
Optional/Challenge:
If you want to deal with color images, you can use imageToPixelsColor,
which will return an array of java.awt.Color objects. See the Java API
for details, but the most useful color methods are getRed(), setRed(int),
and similarly for green and blue. To display a color image (if you have
a 2-D array of Colors), call displayAsImage( Color[][] ).
| Constructor Summary | |
|---|---|
Pict()
|
|
| Method Summary | |
|---|---|
static void |
displayPixels(java.awt.Color[][] pixels)
Given an array of Colors, draw it as a Color image. |
static void |
displayPixels(int[][] pixels)
Given an array of grayscale values in [0,256), draw it as a black-and-white image. |
static int[][] |
fileToPixelsBW(java.lang.String filenameOrURL)
Given a filename or URL, return a 2-D array of grayscale values in [0,256). |
static java.awt.Color[][] |
fileToPixelsColor(java.lang.String filenameOrURL)
Given a filename or URL, return a 2-D array of java.awt.Colors. |
static void |
main(java.lang.String[] args)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Pict()
| Method Detail |
|---|
public static void displayPixels(java.awt.Color[][] pixels)
pixels - A 2-D array of java.awt.Colors.public static void displayPixels(int[][] pixels)
pixels - A 2-D array of grayscale values in [0,256).public static int[][] fileToPixelsBW(java.lang.String filenameOrURL)
filenameOrURL - A string like "H:\MyFile.jpeg" or "http://www.radford.edu/someUser/somePict.jpg"
public static java.awt.Color[][] fileToPixelsColor(java.lang.String filenameOrURL)
filenameOrURL - A string like "H:\MyFile.jpeg" or "http://www.radford.edu/someUser/somePict.jpg"
public static void main(java.lang.String[] args)