网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

java代码获取图片文字 java上传图片代码

java 如何读取附加到图片上的文字

图片上的文字是没法读取的,以为这涉及到图像处理。非常非常复杂!因为如果你非要读取图片上的文字,不是几行代码可以搞定的,首相从matlaB开始学,了解什么是图像处理。然后再开发相应的jar包。当然,你也可以使用相关的软件工具,比如识图软件,通过读取软件的反馈也算是读取了图片上的文字

在渝水等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都做网站、成都网站设计 网站设计制作按需开发,公司网站建设,企业网站建设,品牌网站设计,成都营销网站建设,成都外贸网站建设,渝水网站建设费用合理。

通过文字搜索图片 java代码实现及说明

import ja.io.*;

//获取文件夹内容

public class getthing

{

public static void main(String[] args) throws Exception

{

System.out.println(welstr);

listFile(new File("e:\\aa")); //想要搜索的路径

}

public static void listFile(File file) throws Exception

{

if(file.isFile())

{

//输出的是完整的文件夹内文件的路径

System.out.println("File :"+file.getAbsolutePath());

//01.jpg就是你要找的图片

if (file.getAbsolutePath().endsWith("01.jpg"))

System.out.println("有搜索的图片");

}

else

{

System.out.println("Dir :"+file.getAbsolutePath());

File[] files =file.listFiles();

for(int i=0;ifiles.length;i++)

{

listFile(files[i]);

System.out.println("回车");

}

}

}

}

1 首先确定你要搜索的目录

2 要搜索的关键字 如“花”

3 只搜索图片类型 .jpg .gif .png .bmp之类的

4 在文本框里获得搜索的关键字

5 取得要搜索目录下的所有图片类型的名字

6 用关键字和取得的文件名一一进行对比

7 若有关键字 记录该图片的名字

8 若都没关键字 表示无该名字的图片

9 空白区域你可以用一个窗体来表示

10 把搜索到的图片都显示在这个窗体。

如何利用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 zhi/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;itext1.length;i++)

{

g.drawString(text1[i],0,fontsize+i*fontsize);

}

g.dispose();

FileOutputStream out = new FileOutputStream("E:\\dian zi za zhi/789.jpg");

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);

encoder.encode(image);

out.close(); 答案补充 public static void main(String[] args) {

// TODO Auto-generated method stub

hh("sdakljsdhwwbr/asdasdbr/a");

}

}

试试 可以换行 答案补充 关于 图片的尺寸以及字体是否超出 你自己试着解决下 不要过于依赖问

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 copy 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.edu.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 copy 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.edu.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 codeimage .* @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;

}

资源来自:


名称栏目:java代码获取图片文字 java上传图片代码
地址分享:http://bjjierui.cn/article/dooihgo.html

其他资讯