欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

java代碼符號(hào)實(shí)現(xiàn)圖片,java圖標(biāo)圖片

如何用java代碼實(shí)現(xiàn)手動(dòng)點(diǎn)擊圖片更換想要換的圖片替換

一個(gè)圖片時(shí)你知道,現(xiàn)在只是切換的問題?

創(chuàng)新互聯(lián)是專業(yè)的大名網(wǎng)站建設(shè)公司,大名接單;提供成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、成都外貿(mào)網(wǎng)站建設(shè)公司,網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行大名網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!

給按鈕添加一個(gè) ActionListener,在它的 actionPerformed 方法中做你的事情,把 jpanel.setIcon(..) 換張圖片。

請(qǐng)問 用java語句輸出如圖片圖案應(yīng)該怎么做?

1、代碼如下:

public class Main

{

public static void main(String[] args) {

System.out.println("Hello World!");

//主循環(huán)

? for(int i =10;i0;i--){

? ? ? //輸出空格

? ? ? for(int k=i;k0;k--){System.out.print(" ");}

//輸出數(shù)字

? ? ? for(int j=i;j=10;j++){

? ? ? ? ? System.out.print(j+" ");? ? ? ? ? ? ?

? ? ? }System.out.println(" ");

? }

}

}

2、效果如圖

怎么樣用Java實(shí)現(xiàn)將一張圖片轉(zhuǎn)成字符畫??

#首先在D盤寫一個(gè)文件"temp.html",如下內(nèi)容

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

html

head

title圖片轉(zhuǎn)文本/title

meta http-equiv="content-type" content="text/html; charset=gbk"

style type="text/css"

body {

font-family: 宋體; line-height: 0.8em; letter-spacing: 0px; font-size: 8px;

}

/style

/head

body

${content}

/body

/html

#在D盤放一個(gè)圖片(放小一點(diǎn)的)"a.jpg"

#運(yùn)行如下JAVA代碼:

import java.awt.Color;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStreamReader;

import javax.imageio.ImageIO;

public class Test {

/** 此處設(shè)置灰度字符,此處只用十個(gè)字符,可以設(shè)置更多 */

private static char[] cs = new char[] { '.', ',', '*', '+', '=', '', '$', '@', '#', ' ' };

public static void main(String[] args) throws IOException {

// 讀取圖片

BufferedImage bfedimage = ImageIO.read(new File("D:\\a.jpg"));

// 圖片轉(zhuǎn)字符串后的數(shù)組

char[][] css = new char[bfedimage.getWidth()][bfedimage.getHeight()];

for (int x = 0; x bfedimage.getWidth(); x++) {

for (int y = 0; y bfedimage.getHeight(); y++) {

int rgb = bfedimage.getRGB(x, y);

Color c = new Color(rgb);

// 得到灰度值

int cc = (c.getRed() + c.getGreen() + c.getBlue()) / 3;

css[x][y] = cs[(int) ((cc * 10 - 1) / 255)];

}

}

// 取得模板HTML

String temp = readFile(new File("D:\\temp.html"),"gbk");

StringBuffer sb = new StringBuffer();

// 開始拼接內(nèi)容

for (int y = 0; y css[0].length; y++) {

for (int x = 0; x css.length; x++) {

sb.append(css[x][y]);

}

sb.append("\r\n");

}

System.out.println(sb.toString());

// 生成文件

String content = toHTML(sb.toString());

String filecontent = replaceStrAllNotBack(temp, "${content}", content);

writeFile(new File("D:\\content.html"), filecontent, "gbk");

}

public static String toHTML(String s) {

s = s.replaceAll("", "");

s = s.replaceAll(" ", "?");

s = s.replaceAll("", "");

s = s.replaceAll("", "");

s = s.replaceAll("\"", """);

s = s.replaceAll("\\\r\\\n", "br/");

s = s.replaceAll("\\\r", "br/");

s = s.replaceAll("\\\n", "br/");

return s;

}

public static String replaceStrAllNotBack(String str, String strSrc, String strDes) {

StringBuffer sb = new StringBuffer(str);

int index = 0;

while ((index = sb.indexOf(strSrc, index)) != -1) {

sb.replace(index, index + strSrc.length(), strDes);

index += strDes.length();

}

return sb.toString();

}

/**

* 讀文件(使用默認(rèn)編碼)

*

* @param file

* @return 文件內(nèi)容

* @throws IOException

*/

public static String readFile(File file, String charset) throws IOException {

InputStreamReader fr = new InputStreamReader(new FileInputStream(file), charset);

StringBuffer sb = new StringBuffer();

char[] bs = new char[1024];

int i = 0;

while ((i = fr.read(bs)) != -1) {

sb.append(bs, 0, i);

}

fr.close();

return sb.toString();

}

/**

* 寫文件

*

* @param file

* @param string

* 字符串

* @param encoding

* 編碼

* @return 文件大小

* @throws IOException

*/

public static int writeFile(File file, String string, String encoding) throws IOException {

FileOutputStream fos = new FileOutputStream(file);

try {

byte[] bs = string.getBytes(encoding);

fos.write(bs);

return bs.length;

} finally {

fos.close();

}

}

}

#打開"D:\content.html"文件看效果吧。

有什么問題可以聯(lián)系我。

本文題目:java代碼符號(hào)實(shí)現(xiàn)圖片,java圖標(biāo)圖片
標(biāo)題鏈接:http://chinadenli.net/article48/hesoep.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版品牌網(wǎng)站設(shè)計(jì)建站公司網(wǎng)站制作靜態(tài)網(wǎng)站

廣告

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

網(wǎng)站托管運(yùn)營