欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

如何在java中將圖像轉(zhuǎn)換為字符畫

如何在java中將圖像轉(zhuǎn)換為字符畫?針對這個問題,這篇文章詳細介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

目前創(chuàng)新互聯(lián)已為數(shù)千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、綿陽服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計、靈璧網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

Java是什么

Java是一門面向?qū)ο缶幊陶Z言,可以編寫桌面應(yīng)用程序、Web應(yīng)用程序、分布式系統(tǒng)和嵌入式系統(tǒng)應(yīng)用程序。

具體內(nèi)容如下

public class ImageProcesser { 
  
 private static final char[] charset1 = {'M','8','V','|',':','.',' '}; //默認字符素材集 
 private char[] charset; //字符畫素材集 
 private String imgString = ""; //儲存轉(zhuǎn)化后的字符串 
  
  
 //使用指定字符集構(gòu)造 
 public ImageProcesser(char[] charset){ 
  this.charset = charset; 
 } 
 //使用默認字符集構(gòu)造 
 public ImageProcesser(){ 
  this.charset = charset1; 
 } 
  
 public String getImgString(){ 
  return imgString; 
 } 
 
 /*將圖形文件轉(zhuǎn)化為字符畫字符串*/ 
 public ImageProcesser toBitmapConvert(String imagepath){ 
  return toBitmapConvert(new File(imagepath)); 
 } 
 public ImageProcesser toBitmapConvert(File imageFile){ 
   
  StringBuffer sb = new StringBuffer(); 
  if(!imageFile.exists()){ //當(dāng)讀取的文件不存在時,結(jié)束程序 
   System.out.println("File is not exists!"); 
   System.exit(1); 
  } 
  Color color; 
  try{ 
   BufferedImage buff = ImageIO.read(imageFile); //將圖片文件裝載如BufferedImage流 
   buff = compressImage(buff); 
  
   int bitmapH = buff.getHeight(); 
   int bitmapW = buff.getWidth(); 
    
   //逐行掃描圖像的像素點,讀取RGB值,取其平均值,并從charset中獲取相應(yīng)的字符素材,并裝載到sb中 
   for(int y=0; y<bitmapH; y++){    
    for(int x=0; x<bitmapW; x++){ 
     int rgb = buff.getRGB(x,y); 
     color = new Color(rgb); 
      
     int cvalue = (color.getRed()+color.getGreen()+color.getBlue()) / 3; 
     sb.append(charset[(int)((cvalue * charset.length - 1)/255)]+" "); 
    } 
    sb.append("\r\n"); 
   } 
  }catch(IOException ex){ 
   ex.printStackTrace(); 
  } 
  imgString = sb.toString(); 
  return this; 
 } 
  
  
 /*圖像文件預(yù)處理:將圖片壓縮到 最長邊為 100px*/ 
 private BufferedImage compressImage(BufferedImage srcImg){ 
  int h = srcImg.getHeight(); 
  int w = srcImg.getWidth(); 
  if(Math.max(h,w)<=100) 
   return srcImg; 
  int new_H; 
  int new_W; 
  if(w>h){ 
   new_W = 100; 
   new_H = 100*h/w ; 
  }else{ 
   new_H = 100; 
   new_W = 100*w/h; 
  } 
  BufferedImage smallImg = new BufferedImage(new_W,new_H,srcImg.getType()); 
  Graphics g = smallImg.getGraphics(); 
  g.drawImage(srcImg,0,0,new_W,new_H,null); 
  g.dispose(); 
  return smallImg; 
 } 
  
 /*將字符串保存為.txt文件*/ 
 public void saveAsTxt(String fileName){ 
  try{ 
   PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(fileName))); 
   for(int i = 0;i<imgString.length();i++){ 
    out.print(imgString.charAt(i)); 
   } 
   out.close(); 
    
  }catch(IOException ex){ 
   ex.printStackTrace(); 
  } 
 } 
  
 /*批處理圖像文件*/ 
 public static void batchImgFile(String srcfile, String tragetfile){ 
   
  File folder = new File(tragetfile); //生成圖片的文件夾 
  File srcfolder = new File(srcfile); 
  if(!folder.exists() || !folder.isDirectory()) 
   folder.mkdirs(); 
  ImageProcesser processer = new ImageProcesser(); 
  File[] filelist = srcfolder.listFiles(); 
   
  for(int i=0;i<filelist.length;i++){ 
   if(!filelist[i].isFile()) 
    continue; 
   processer.toBitmapConvert(filelist[i]); 
   processer.saveAsTxt(tragetfile+"/"+(i+1)+".txt"); 
   System.out.println(filelist[i].getName()+" is converted!"); 
  } 
  System.out.println("All img were converted!"); 
   
 } 
 
}

關(guān)于如何在java中將圖像轉(zhuǎn)換為字符畫問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。

網(wǎng)頁標題:如何在java中將圖像轉(zhuǎn)換為字符畫
網(wǎng)頁網(wǎng)址:http://aaarwkj.com/article34/peiepe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、企業(yè)網(wǎng)站制作、品牌網(wǎng)站設(shè)計、網(wǎng)站設(shè)計公司Google、網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站
在线日韩观看免费av| 亚洲免费一级黄色录像片| 一区二区在线日韩欧美| 黄色免费av片在线观看| 清纯少妇激情四射网站| 亚州欧美精品一区二区| 国产原创传媒在线观看| 欧美日本一道本一区二区三区| 国产女孩精品在线播放| 91激情黑丝在线观看| 少妇高潮视频在线观看| 久久国产精品乱码电影| 日韩精品少妇一区二区在线看| 国产男女猛进猛出精品91| 日本一区二区三区免费不卡视频 | 麻豆一区二区人妻网站| 中文字幕av免费专区| 麻豆av永久地址久久精品| 色噜噜人妻av中文字幕| 午夜啪视频免费在线观看| 欧美日韩国产激情另类| 天堂在线精品亚洲综合网| 18末年禁止观看免费软件| 欧美日韩在线亚洲二区综二 | 伊人丁香六月日日操操| 熟妇高潮一区二区三区| 国产又粗又长又爽网站| 日日躁夜夜躁久久狠狠躁| 日韩精品视频在线观看| 国产高清不卡一二三区| 99精品国产中文字幕| 亚洲综合欧美日韩一区| 一区二区日韩激情在线观看视频| 午夜视频在线观看免费高清国产 | 91青青草原免费观看| 最新中文字幕成人在线观看| 欧美一区二区高清不卡| 国内精品自产拍久久久久久久久91| 国产精品主播自拍视频| 91人妻互换一区二区| 综合久久—本道中文字幕|