posts - 70,comments - 408,trackbacks - 0

          package common;
          /**
          ?* 網(wǎng)絡(luò)圖片掃描程序
          ?*
          ?*/

          import java.awt.image.BufferedImage;
          import java.io.File;
          import java.io.FileOutputStream;
          import java.io.FilterInputStream;

          import javax.imageio.ImageIO;

          import com.asprise.util.ocr.OCR;
          import java.net.*;


          public class ImageWord {
          ?//獲得圖片數(shù)字
          ?public static String word(String str) {
          ??try {
          ???File file = new File(str);
          ???BufferedImage image = ImageIO.read(file);
          ???String s = new OCR().recognizeCharacters(image);
          ???return s;
          ??} catch(Exception e) {
          ???return "";
          ??}
          ?}
          ?//刪除臨時(shí)目錄的圖片
          ?public static void deleteImage() {
          ??try {
          ???String path = Thread.currentThread().getContextClassLoader().getResource("")+"temp/";
          ???String filePath = path.substring(6,path.length());
          ???File file = new File(filePath);
          ???File[] files = file.listFiles();
          ???for(int i=0;i<files.length;i++) {
          ????try {
          ?????//系統(tǒng)文件不刪除
          ?????if(!(files[i].getName()).equalsIgnoreCase("Thumbs.db")) {
          ??????if(files[i].isFile()) {
          ???????files[i].delete();
          ??????} else if(files[i].isDirectory()) {
          ???????files[i].delete();
          ??????} else {
          ???????files[i].delete();
          ??????}
          ?????}
          ????} catch (RuntimeException e) {
          ?????Print.print("ImageWordError","DELETE FILE ERROR");
          ????}
          ???}
          ??} catch (RuntimeException e) {
          ???Print.print("ImageWordError","圖片刪除失敗Error!"+e.toString());
          ??}
          ?}
          ?//保存圖片到臨時(shí)目錄
          ?public static String saveImage(String image) {
          ??try {
          ???if(image.length()>1024) {
          ????return null;
          ???}
          ???if(image.equals("")) {
          ????return null;
          ???}
          ???String fileName = image.substring(image.lastIndexOf("/")+1,image.length());
          ???String path = Thread.currentThread().getContextClassLoader().getResource("")+"temp/"+fileName;
          ???String filePath = path.substring(6,path.length());
          ???URL? url = null;
          ???try {
          ???? url = new URL(image);
          ???} catch(Exception e) {
          ???? Print.print("ImageWordError","URL ERROR");
          ???? return null;
          ???}
          ???FilterInputStream in=(FilterInputStream) url.openStream();
          ???File fileOut=new File(filePath);
          ???FileOutputStream out=new FileOutputStream(fileOut);
          ???byte[] bytes=new byte[1024];
          ???int c;
          ???while((c=in.read(bytes))!=-1) {
          ????out.write(bytes,0,c);
          ???}
          ???in.close();
          ???out.close();
          ???return filePath;
          ??} catch(Exception e) {
          ???Print.print("ImageWordError","圖片保存失敗Error!"+e.toString());
          ???return null;
          ??}
          ?}
          }

          ?

          posted on 2007-03-21 10:02 我心依舊 閱讀(1397) 評(píng)論(4)  編輯  收藏

          FeedBack:
          # re: 自己寫的處理圖片的幾個(gè)方法
          2007-05-11 23:44 | 寶露o(∩_∩)o
          請(qǐng)問(wèn)這個(gè)包是哪里的啊?  回復(fù)  更多評(píng)論
            
          # re: 自己寫的處理圖片的幾個(gè)方法
          2007-05-12 09:01 | 我心依舊
          com.asprise.util.ocr.OCR?
          一個(gè)開源包,是提取圖片中的相關(guān)字符的.  回復(fù)  更多評(píng)論
            
          # re: 自己寫的處理圖片的幾個(gè)方法
          2008-05-04 06:47 | 我愛浪子
          @我心依舊
          這個(gè)開源包的下載地下呢?

          先就要介紹這個(gè)的,,可你沒有寫!  回復(fù)  更多評(píng)論
            
          # re: 自己寫的處理圖片的幾個(gè)方法[未登錄]
          2008-09-12 12:01 | 阿甘
          你好,能給我這開源包和教程嗎?我正在做一OA項(xiàng)目,要用到OCR,謝謝
          我的EMAIL:gl74gs48@tom.com  回復(fù)  更多評(píng)論
            

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 尉氏县| 阜新| 理塘县| 清流县| 襄汾县| 江孜县| 宜黄县| 宜君县| 高雄市| 灌阳县| 临沧市| 岚皋县| 水城县| 乌兰县| 罗甸县| 江津市| 镇坪县| 兖州市| 从化市| 南昌县| 绥棱县| 尉犁县| 丹江口市| 丘北县| 休宁县| 广宗县| 凭祥市| 巴南区| 临澧县| 西吉县| 永春县| 比如县| 鸡西市| 神农架林区| 莒南县| 香港| 唐山市| 临泉县| 蓬莱市| 鹿邑县| 永德县|