posts - 70,comments - 408,trackbacks - 0

          package common;
          /**
          ?* 網絡圖片掃描程序
          ?*
          ?*/

          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 {
          ?//獲得圖片數字
          ?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 "";
          ??}
          ?}
          ?//刪除臨時目錄的圖片
          ?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 {
          ?????//系統文件不刪除
          ?????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());
          ??}
          ?}
          ?//保存圖片到臨時目錄
          ?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 我心依舊 閱讀(1406) 評論(4)  編輯  收藏

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

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

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 香港 | 美姑县| 类乌齐县| 拜城县| 从化市| 昌乐县| 冷水江市| 镇康县| 遂昌县| 疏勒县| 布拖县| 平安县| 永定县| 和顺县| 乳源| 准格尔旗| 秦安县| 巧家县| 利津县| 兴义市| 竹溪县| 康定县| 台前县| 贵州省| 平度市| 沙洋县| 郸城县| 阳曲县| 农安县| 定襄县| 玉树县| 玉门市| 平远县| 靖安县| 临汾市| 原阳县| 响水县| 措美县| 青岛市| 贵溪市| 大方县|