国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

java實(shí)現(xiàn)圖片用Excel畫出來

瀏覽:89日期:2022-05-30 17:54:21

本文實(shí)例為大家分享了java用Excel將圖片畫出來的具體代碼,供大家參考,具體內(nèi)容如下

能夠?qū)⑷魏螆D片在excel上利用單元格背景完整的描繪出來。

像網(wǎng)絡(luò)上出現(xiàn)的用excel畫出超級瑪麗等等,各種圖片都能在excel上'畫'出來。

圖片我沒有經(jīng)過特殊處理,所以轉(zhuǎn)換的圖片不能太大,有多大的圖片就要有多少的單元格。如640*480就有307200的單元格。

如要轉(zhuǎn)換的圖片:

java實(shí)現(xiàn)圖片用Excel畫出來

轉(zhuǎn)換后在excel中的效果:

java實(shí)現(xiàn)圖片用Excel畫出來

沒多大意義練練手:

import java.awt.Color;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import java.util.Locale; import javax.swing.ImageIcon; import jxl.Workbook;import jxl.WorkbookSettings;import jxl.format.Colour;import jxl.read.biff.BiffException;import jxl.write.Label;import jxl.write.WritableCellFormat;import jxl.write.WritableSheet;import jxl.write.WritableWorkbook; public class Helper { private BufferedImage getBufferedImage(String filepath) { ImageIcon imgicon=new ImageIcon(filepath); BufferedImage bufferedImage = new BufferedImage(imgicon.getIconWidth(),imgicon.getIconHeight(),BufferedImage.TYPE_INT_RGB); bufferedImage.createGraphics().drawImage(imgicon.getImage(), 0, 0,null); return bufferedImage; } private Colour getNearestColour(Color awtColor) { Colour color = null; Colour[] colors = Colour.getAllColours(); if ((colors != null) && (colors.length > 0)) { Colour crtColor = null; int[] rgb = null; int diff = 0; int minDiff = 999; for (int i = 0; i < colors.length; i++) { crtColor = colors[i]; rgb = new int[3]; rgb[0] = crtColor.getDefaultRGB().getRed(); rgb[1] = crtColor.getDefaultRGB().getGreen(); rgb[2] = crtColor.getDefaultRGB().getBlue(); diff = Math.abs(rgb[0] - awtColor.getRed()) + Math.abs(rgb[1] - awtColor.getGreen()) + Math.abs(rgb[2] - awtColor.getBlue()); if (diff < minDiff) { minDiff = diff; color = crtColor; } } } if (color == null) color = Colour.BLACK; return color; } public void exec(String convertFromImage,String createxls) throws Exception { WorkbookSettings ws = new WorkbookSettings(); ws.setLocale(new Locale('en', 'EN')); WritableWorkbook workbook = Workbook.createWorkbook(new File(createxls), ws); WritableSheet s2 = workbook.createSheet('picture', 0); BufferedImage buffimage= getBufferedImage(convertFromImage); int width=buffimage.getWidth(); int heigh=buffimage.getHeight(); for(int i=0;i<width;i++) { for(int h=0;h<heigh;h++) { WritableCellFormat greyBackground = new WritableCellFormat(); Color c = new Color(buffimage.getRGB(i, h));greyBackground.setBackground( getNearestColour(c) ); Label lr = new Label(i, h, '', greyBackground); s2.addCell(lr); } } //寫入Excel對象 workbook.write(); workbook.close(); } /** * @param args * @throws IOException * @throws BiffException */ public static void main(String[] args) throws Exception { Helper helper=new Helper(); System.out.println('輸入的圖片:'+args[0]); System.out.println('輸出的excel:'+args[1]); System.out.println('轉(zhuǎn)換開始'); //轉(zhuǎn)換執(zhí)行的方法參數(shù) args[0]輸入的圖片路徑 args[1]輸出的excel路徑// helper.exec( 'mslogo.jpg','1.xls'); helper.exec(args[0],args[1]); } }

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: excel
相關(guān)文章:
主站蜘蛛池模板: 欧美国产永久免费看片 | 男人天堂久久 | 在线播放人成午夜免费视频 | 农村三级孕妇视频在线 | 91热久久免费频精品动漫99 | 亚洲第一网站免费视频 | 一区二区日韩 | 国产欧美日韩在线不卡第一页 | bt天堂国产亚洲欧美在线 | 中文日韩字幕 | 精品九九在线 | 色老头老太做爰视频在线观看 | 男人一进一出桶女人视频 | 亚洲欧美日韩国产一区二区精品 | 日本作爱 | 欧美大片毛片aaa免费看 | 欧美a级完整在线观看 | 国产在线观看免费一级 | 一级做a爰在线就看 | 国产成人高清一区二区私人 | 免费一区二区三区久久 | 麻豆传媒一区 | 国产黄色激情视频 | 99久久精品久久久久久清纯 | 在线看国产 | 免费视频一区二区三区四区 | 久久久国产99久久国产一 | 免费永久观看美女视频网站网址 | 日本一区二区免费在线观看 | 欧美视频在线观看一区二区 | 亚洲国产成人精品久久 | 日本毛片在线观看 | 久久这| 成人在线视频免费看 | 国产精选在线视频 | 亚洲欧美日产综合在线看 | 成人欧美视频在线看免费 | 欧美一级毛片aaa片 欧美一级毛片不卡免费观看 | 亚洲视频综合网 | 精品中文字幕久久久久久 | 国产欧美成人一区二区三区 |