导航:首页 > 文字图片 > 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图片文字相关的资料

热点内容
怎么装修房子的图片 浏览:995
校园建筑速写图片临摹简单 浏览:656
男同裸体电影推荐 浏览:213
动漫女生傲娇图片 浏览:102
月饼速写图片简单又漂亮 浏览:120
幼儿中班最简单手工图片 浏览:420
可爱的饺卡通子图片 浏览:799
松山战役娃娃兵的电影名字叫什么 浏览:78
免费电影网APP 浏览:529
维语全部电影 浏览:13
后舍的男生图片 浏览:814
宿舍美女拍照图片 浏览:886
幸运的13号战机在线观看 浏览:674
男装特价衣服图片 浏览:573
跟鸡有关的电影 浏览:553
电影分好看片的是哪个网了 浏览:269
和草灯和尚类似 浏览:176
狙击电影美国免费看 浏览:496
动漫封面图片男生帅气酷 浏览:536
林正英100部鬼片粤语 浏览:291