導航:首頁 > 文字圖片 > java圖片文字

java圖片文字

發布時間:2022-06-30 21:47:38

❶ java 實現圖片的文字識別

摘要圖像識別是目前很熱門的研究領域,涉及的知識很廣,包括資訊理論、模式識別、模糊數學、圖像編碼、內容分類等等。本文僅對使用Java實現了一個簡單的圖像文本二值處理,關於識別並未實現。
步驟
建立文本字元模板二值矩陣
對測試字元進行二值矩陣化處理
代碼
/*
* @(#)StdModelRepository.java
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
* You should have received a of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package cn.e.ynu.sei.recognition.util;import java.awt.Image;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import java.util.ArrayList;import java.util.List;import java.util.logging.Level;import java.util.logging.Logger;import javax.imageio.ImageIO;/** * Hold character charImgs as standard model repository.
* @author 88250
* @version 1.0.0.0, Mar 20, 2008
*/
public class StdModelRepository {
/** * hold character images
*/ List charImgs = new ArrayList();
/** * default width of a character
*/ static int width = 16 /** * default height of a character
*/ static int height = 28 /** * standard character model matrix
*/ public int[][][] stdCharMatrix = new int[27][width][height];
/** * Default constructor.
*/ public StdModelRepository() {
BufferedImage lowercase = null try {
lowercase = ImageIO.read(new File("lowercase.png"));
} catch (IOException ex) {
Logger.getLogger(StdModelRepository.class.getName()).
log(Level.SEVERE, null, ex);
}
for (int i = 0 i < 26 i++) {
charImgs.add(lowercase.getSubimage(i * width,
0,
width,
height));
}
for (int i = 0 i < charImgs.size(); i++) {
Image image = charImgs.get(i);
int[] pixels = ImageUtils.getPixels(image,
image.getWidth(null),
image.getHeight(null));
stdCharMatrix[i] = ImageUtils.getSymbolMatrix(pixels, 0).clone();
ImageUtils.displayMatrix(stdCharMatrix[i]);
}
}
}
/*
* @(#)ImageUtils.java
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
* You should have received a of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package cn.e.ynu.sei.recognition.util;import java.awt.Image;import java.awt.image.PixelGrabber;import java.util.logging.Level;import java.util.logging.Logger;/** * Mainipulation of image data.
* @author 88250
* @version 1.0.0.3, Mar 20, 2008
*/
public class ImageUtils {
/** * Return all of the pixel values of sepecified <code>image< .>* @param image the sepecified image
* @param width width of the image
* @param height height of the image
* @return */ public static int[] getPixels(Image image, int width, int height) {
int[] pixels = new int[width * height];
try {
new PixelGrabber(image, 0, 0, width, height, pixels, 0, width).grabPixels();
} catch (InterruptedException ex) {
Logger.getLogger(ImageUtils.class.getName()).
log(Level.SEVERE, null, ex);
}
return pixels;
}
資源來自:
http://blog.csdn.net/chief1985/article/details/2229572

如何實現java畫圖程序,並可在已畫的圖上添加文字等,求大神T-T

只提指導,沒有源碼。
在 Java 中要自定義組件,一般是覆蓋掉 protected void paintComponent(Graphics g); 方法就可以了,對於你這個類似畫筆的程序,首先,整個畫布是一個自定義的繼承自像 JPanel 一樣的東西,不過我們需要覆蓋它的 paintComponent 方法,因為:一、我們需要在當滑鼠拖放一個東西時我們移動這個選中的圖形時記住它的位置;二、設定 label 時需要保存它的 Label。三、知道圖形的形狀。
,然後在 paintComponent 時依次畫出各個圖形來。

要繪圖:

1、直線,g.drawLine(x,y,x2,y2); // 參數分別是起止點坐標。
2、矩形,g.fillRect(x, y, w, h); // 參數分別是左上角坐標和寬及高。
3、橢圓,g.fillOval(x, y, w, h); // 參數分別是橢圓形的外切矩形的左上角坐標及寬和高,當w 和 h 相等時是個圓。

准備繪圖前 g.setColor() 設置前景色;先把整個畫布用 g.fillRect() 塗成白色,再分別畫各個圖形,最後繪制 Label 應該在畫圖形之後再做。

移動圖形,是給 畫布組件 addMouseMotionListener 來監聽事件的,在拖動時先通過 mouseDragged 事件的 MouseEvent.point 知道它的位置是在哪個圖形的內部,之後的移動就修改這個圖形的位置。

❸ java 在圖片中填寫文字,字體大小自適應自動換行

如果強制換行的話,就在要換行的文字處插入游標,然後按住alt+enter鍵,就可以了。至於能不能顯示兩行文字就看格子有沒有那麼高了。

❹ 如何在java的背景圖片上添加文字

import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;

public class DrawString extends Frame{

private static final int spacing = 20 ; //文字與圖片邊界的空白
private static final int wordNum = 7; //文字字型大小

private Color strColor;
private StringBuffer message;
private int pictureWidth;
private int pictureHight;

public void paint(Graphics g){
Color c = g.getColor();
g.setColor(strColor);

StringBuffer msg = message;

int strNumPerLine = (pictureWidth - spacing) / wordNum;
int strLineNum = message.length() / strNumPerLine;

for(int l=strLineNum,n=0 ;l<0; l--){

msg.substring(n, strNumPerLine);
g.drawString(msg.toString(), wordNum, wordNum * strNumPerLine);

n = strNumPerLine;
}

g.setColor(c);
//this.draw(g);

}

public DrawString(Color strColor, StringBuffer message, int pictureWidth, int pictureHight) {

this.strColor = strColor;
this.message = message;
this.pictureWidth = pictureWidth;
this.pictureHight = pictureHight;

}

}

❺ 如何利用java在圖片上添加文字

// 讀取模板圖片內容
BufferedImage image = ImageIO.read(new FileInputStream("c:\\test.jpg"));
Graphics2D g = image.createGraphics();// 得到圖形上下文
g.setColor(Color.BLACK); // 設置畫筆顏色
// 設置字體
g.setFont(new Font("宋體", Font.LAYOUT_LEFT_TO_RIGHT, 15));// 寫入簽名
// 下面這一句中的43,image.getHeight()-10可以改成你要的坐標。
g.drawString("這是新加入的文字", 43, image.getHeight() - 10);
g.dispose();
FileOutputStream out = new FileOutputStream("c:\\test1.jpg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
希望我的回答能幫助你 謝謝 呵呵 答案補充 肯定了 在一張紙上寫字 肯定會自動換行的 否則寫外面?邏輯都通不過去~ 答案補充 把你的意思說出了 是不是隨便的寫字然後就提交 就把字寫在了圖片上還是?多少字 有沒有約束? 答案補充 g.drawString("這是新加入的文字", 43, image.getHeight() - 10);

在這個做處理 你規定了字體的大小 那麼獲取字元的長度*大小 一次判斷不要大於寬度 否則image.getHeight() - 10++ 你試試 應該可以的 我這里沒有Eclipse 答案補充 public class mains {

/**
* @param args
*/

private static int fontsize = 15;

static String jj(String str)
{
String sContent = str;
sContent=sContent.replaceAll(" "," ");
sContent=sContent.replaceAll("<br/>","/");
sContent=sContent.replaceAll("<br>","/");

return sContent;
} 答案補充 static void hh(String str)
{
BufferedImage image;
try {
image = ImageIO.read(new FileInputStream("E:\\dian zi za /789.jpg"));
Graphics2D g = image.createGraphics();// 得到圖形上下文
g.setColor(Color.BLACK); // 設置畫筆顏色
// 設置字體
g.setFont(new Font("宋體", Font.LAYOUT_LEFT_TO_RIGHT, fontsize));// 寫入簽名
// 下面這一句中的43,image.getHeight()-10可以改成你要的坐標。

String text = jj(str); 答案補充 String [] text1 = text.split("/");

int h = image.getHeight();
int w = image.getWidth();
for(int i=0;i<text1.length;i++)
{

g.drawString(text1[i],0,fontsize+i*fontsize);
}
g.dispose();
FileOutputStream out = new FileOutputStream("E:\\dian zi za /789.jpg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close(); 答案補充 public static void main(String[] args) {
// TODO Auto-generated method stub

hh("sdakljsdhww<br/>asdasd<br/>a");
}

}
試試 可以換行 答案補充 關於 圖片的尺寸以及字體是否超出 你自己試著解決下 不要過於依賴問

❻ java生成jpg圖片 並且實現文字和圖片混排

response.setHeader("Cache-Control","no-cache");
String str="";
String sum="";
for(int i=0;i<4;i++){
Random random=new Random();
int j=Math.round(random.nextFloat()*35);
char x=str.charAt(j);
sum+=x+"";
}
request.getSession().setAttribute("Code",sum);
BufferedImage bufferedImage=new BufferedImage(50,20,BufferedImage.TYPE_3BYTE_BGR);
Graphics2D graphics2D=(Graphics2D)bufferedImage.getGraphics();
graphics2D.setColor(Color.blue);
graphics2D.fill3DRect(0,0,50,20,false);
graphics2D.setColor(Color.YELLOW);
graphics2D.drawString(sum,10,12);
response.setContentType("image/jpeg");
ServletOutputStream output;
try {
output = response.getOutputStream();
JPEGImageEncoder encoder= JPEGCodec.createJPEGEncoder(output);
encoder.encode(bufferedImage);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

❼ java中導入一個圖片,然後在圖片上加上幾個文字再輸出保存,應該如何用代碼實現

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Test{

public static void main(String[] args){
try {
File f1 = new File("a.jpg");
BufferedImage image = ImageIO.read(f1);
Graphics g = image.getGraphics();
g.setFont(new Font("Serif",Font.BOLD,20));
g.setColor(Color.red);
g.drawString("happy new year!", 10, 20);
File f2 = new File(".jpg");
ImageIO.write(image, "JPEG", f2);
} catch (IOException e) {
e.printStackTrace();
}
}
}

❽ Java怎麼在圖片右邊加文字

1、讀取Java本地圖片。
2、讀取網路圖片。
3、創建Java畫筆。
4、添加文字水印。
5、這樣就可以在Java圖片右邊加文字。

❾ java按鈕背景圖片上文字的問題

同問題,找了好久終於解決了。當你設置好Button的文本和背景圖後,在你的按鈕控制項代碼中加上btnNewButton.setHorizontalTextPosition(SwingConstants.CENTER);注意!!!btnNewButton是我按鈕的實例化對象名,用這個指令時把你的實例化按鈕對象名替換了btnNewButton就好了

❿ java 如何讀取附加到圖片上的文字

圖片上的文字是沒法讀取的,以為這涉及到圖像處理。非常非常復雜!因為如果你非要讀取圖片上的文字,不是幾行代碼可以搞定的,首相從matlaB開始學,了解什麼是圖像處理。然後再開發相應的jar包。當然,你也可以使用相關的軟體工具,比如識圖軟體,通過讀取軟體的反饋也算是讀取了圖片上的文字

閱讀全文

與java圖片文字相關的資料

熱點內容
全國最大免費影視 瀏覽:513
黑暗圖片高清 瀏覽:641
至尊寶的那個電影叫什麼 瀏覽:956
跟國旗有關的電影 瀏覽:628
電影《超級營救》 瀏覽:708
最豐滿的美女電影 瀏覽:621
父母生日賀卡簡單圖片 瀏覽:765
看片免費網址 瀏覽:680
豫劇電影農村片 瀏覽:905
自拍網址 瀏覽:611
1vn多男主現代 瀏覽:170
電影國語什麼意思 瀏覽:237
消失的眼角膜完整版視頻在線觀看 瀏覽:413
李采鐔韓國電影大全 瀏覽:576
電影推薦快遞員 瀏覽:881
男主囚禁女主滅了她的國家 瀏覽:722
香港電影一男女papapa完事抽煙 瀏覽:41
陳寶連演的所有電影 瀏覽:559
小清新簡單漫畫圖片 瀏覽:212
成龍電影龍 瀏覽:84