2015-07-21 120 views
1

这样的图像转换算法是如何工作的?android将位图转换为ascii位图

我要位图转换为ASCII位谁能帮助我,我应该是什么样的算法很新的编程

    . W ,     
       W W @     
       W ,W W     
       , W, :W* .W .    
       # WW @WW WW #    
       W WW.WWW WW: W    
       W. WW*WWW# [email protected] W    
      * :[email protected]@W #   
      +* #WW#WWWWWWWWWWWWW# W   
      W# @WWWWWWWWWWWWWWWWW W   
      WW WWWWWWWWWWWWWWWWWW W   
      WW [email protected]#   
     ,WW.WWWWWWWWWWWWWWWWWWWWW   
      [email protected]   
     : WWWWWWWWWWWWWWWWWWWWWWWW :  
     @ [email protected]@@WWWWWW.   
     W*WWWWWW::::@WWW:::::#WWWWW   
     [email protected]:: :+*:. ::@WWWW   
     [email protected]:*:.::  .,.:.:WWWW   
     @WWWW#:.:::.  .:: #:@WWW   
     :[email protected]:#. ::  :WWWW:@WWWW   
     WWW#*:[email protected]*@W  . W:#WWW   
     #WWWW:@  :: :: *WWWW   
     [email protected]*W .::,.::::,:+ @@WW#,  
     WWWW## ,,.: .:::.: . .WWW:,  
     @[email protected]: W..::::: #. :WWWW   
     WWWW:: *..:. ::.,. :WWWW   
     WWWW:: :.:.: : :: ,@[email protected]   
     WWWW: .:, : ,,  :WW,   
     .: #   : ,  : *   
      W + ., ::: ., : @   
      W ::    .: W   
     @,,,W:. ,, ::*@*:, . :@W.,,@  
    +.....*: : : .#WWWWW: : .#:....+,  
    @...:::*:,, : :WWWWWWW, , *::::..,# 
    :...::::::W:, @W::::*W. :W:::::...# 
@@@@@@@@@@@[email protected]@@@@[email protected]@@@@@[email protected]@@@@[email protected]@@@@@@@@@: 

回答

0

这可以很容易地在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); 
    } 

原始来源:

Ascii Art - Java

+1

是Graphics2D的使用上固醇? – Beyka