Java android将位图转换为ascii位图
这样的图像转换算法是如何工作的 我想把一个位图转换成ascii位图。谁能帮我弄清楚我应该用什么样的算法来编程呢Java android将位图转换为ascii位图,java,android,Java,Android,这样的图像转换算法是如何工作的 我想把一个位图转换成ascii位图。谁能帮我弄清楚我应该用什么样的算法来编程呢 . W , W W @ W ,W W , W, :W* .W . # W
. W ,
W W @
W ,W W
, W, :W* .W .
# WW @WW WW #
W WW.WWW WW: W
W. WW*WWW# WW@ W
* :WW.WWWWWWW@WWW@W #
+* #WW#WWWWWWWWWWWWW# W
W# @WWWWWWWWWWWWWWWWW W
WW WWWWWWWWWWWWWWWWWW W
WW WWWWWWWWWWWWWWWWWW@W#
,WW.WWWWWWWWWWWWWWWWWWWWW
WW@WWWWWWWWWWWWWWWWWWWWW
: WWWWWWWWWWWWWWWWWWWWWWWW :
@ WWWWWWWW@WWWWWWW@@WWWWWW.
W*WWWWWW::::@WWW:::::#WWWWW
WWWWWW@:: :+*:. ::@WWWW
WWWWW@:*:.:: .,.:.:WWWW
@WWWW#:.:::. .:: #:@WWW
:WWW@:#. :: :WWWW:@WWWW
WWW#*:W@*@W . W:#WWW
#WWWW:@ :: :: *WWWW
W@WW*W .::,.::::,:+ @@WW#,
WWWW## ,,.: .:::.: . .WWW:,
@WWW@: W..::::: #. :WWWW
WWWW:: *..:. ::.,. :WWWW
WWWW:: :.:.: : :: ,@WW@
WWWW: .:, : ,, :WW,
.: # : , : *
W + ., ::: ., : @
W :: .: W
@,,,W:. ,, ::*@*:, . :@W.,,@
+.....*: : : .#WWWWW: : .#:....+,
@...:::*:,, : :WWWWWWW, , *::::..,#
:...::::::W:, @W::::*W. :W:::::...#
@@@@@@@@@@@W@@@@@W@@@@@@W@@@@@W@@@@@@@@@@:
这在Java中很容易实现
int width = 100;
int height = 30;
//BufferedImage image = ImageIO.read(new File("/logo.jpg"));
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setFont(new Font("SansSerif", Font.BOLD, 24));
Graphics2D graphics = (Graphics2D) g;
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
graphics.drawString("JAVA", 10, 20);
//save this image
//ImageIO.write(image, "png", new File("/ascii-art.png"));
for (int y = 0; y < height; y++) {
StringBuilder sb = new StringBuilder();
for (int x = 0; x < width; x++) {
sb.append(image.getRGB(x, y) == -16777216 ? " " : "$");
}
if (sb.toString().trim().isEmpty()) {
continue;
}
System.out.println(sb);
}
int-width=100;
整数高度=30;
//buffereImage image=ImageIO.read(新文件(“/logo.jpg”);
BuffereImage=新的BuffereImage(宽度、高度、BuffereImage.TYPE_INT_RGB);
Graphics g=image.getGraphics();
g、 setFont(新字体(“SansSerif”,Font.BOLD,24));
Graphics2D graphics=(Graphics2D)g;
graphics.setRenderingHint(renderingHits.KEY\u TEXT\u抗锯齿,
RenderingHints.VALUE\u TEXT\u ANTIALIAS\u ON);
图形。拉丝(“爪哇”,10,20);
//保存此图像
//write(图像,“png”,新文件(“/ascii art.png”);
对于(int y=0;y
原始资料来源:
android上是否提供Graphics2D?