←画像ファイルを
□□□□□□□□□□□□□□□□□■■■■■□□□□□□□□□□□ □□□■■■□□□□□□□□□□■■■■■■■□□□□□□□□□□ ■■■□□□■■□□□□□□□□■■■□□□□■□□■■■■□□□ ■■□□□□□■■□□□□□□■■■□□□□□■■■□□□□■■□ ■■■□□□□□■■■□□□□■■■■■■■■□■□□□□□□■□ □■■■□□□□□■■■□■■■■■□□□□□□■□□□□□□□■ □□■■■□□■■■■■■□□■■■□□□□□□■□□□□■■□■ □□□□■■■□□□■■■■□□■■■□□■□□■□□□■■■■■ □□□□□□□□□□□■■■■□□□■■■□□□■□□□■■■■□ □□□□□□□□□□□□■■■■□□□□□□□■□□□□■■■■□ □□□□□□□□□□□□□■■■■■□□■■■□□□□□□□□□□ □□□□□□□□□□□□□□■■■■■■■■□□□□□□□□□□□ □□□□□□□□□□□□□□□□■■■■□□□□□□□□□□□□□のようなキャラクターに変換。
●コンパイル
javac DotImage.java
●サンプルプログラムソース"DotImage.java"
javac DotImage.java
●サンプルプログラムソース"DotImage.java"
public class DotImage extends java.applet.Applet{ public void init(){ try{ java.awt.TextArea textArea = new java.awt.TextArea( 12, 80 ); textArea.setFont( new java.awt.Font( "Courier", java.awt.Font.PLAIN, 8 ) ); add( textArea ); java.net.URL url = new java.net.URL( getCodeBase(), "toonkigou.gif" ); java.awt.image.BufferedImage image = javax.imageio.ImageIO.read( url ); int iWidth = image.getWidth(); int iHeight= image.getHeight(); for( int y=0; y < iHeight; y++ ){ for( int x=0; x < iWidth; x++ ){ int iPercentage = 0; int iPixel= image.getRGB( x, y ); iPercentage += (iPixel & 0x00ff0000) >>> 16; iPercentage += (iPixel & 0x0000ff00) >>> 8; iPercentage += (iPixel & 0x000000ff); iPercentage = java.lang.Math.round( ( 100 * iPercentage ) / 3 / 255 ); textArea.append( 50 > iPercentage ? "■" : "□" ); } textArea.append( "\n" ); } }catch( Exception e ){ e.printStackTrace(); } } }