将位图上的文本转换为字符串android

时间:2013-04-11 08:35:48

标签: android encoding bitmap bitmapfactory

我试图通过将位图转换为字节数组然后将字节数组转换为String来设置OCR功能..这就是我尝试过的方法

{
            mBitmap =  Bitmap.createBitmap (mContent.getWidth(), mContent.getHeight(), Bitmap.Config.RGB_565);
            img.setImageBitmap(mBitmap);
        }
        Canvas canvas = new Canvas(mBitmap);
        try
        {
            FileOutputStream mFileOutStream = new FileOutputStream(mypath);
            img.setImageBitmap(mBitmap);
            v.draw(canvas);
            mBitmap.compress(Bitmap.CompressFormat.PNG, 90, mFileOutStream);
            ByteArrayOutputStream boas = new ByteArrayOutputStream();
            mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, boas);
            byte[] b = boas.toByteArray();
            String str3=b.toString();
            Log.i("string ", "***** "+str3);
            String str = Base64.encodeToString(b, Base64.DEFAULT);
            txt.setText("STR  "+str);
            Log.i("string ", "****str***** "+str);
            String str2 = new String(b,"UTF-8");
            Log.i("string ", "****str***** "+str2);
            mFileOutStream.flush();
            mFileOutStream.close();
            String url = Images.Media.insertImage(getContentResolver(), mBitmap, "title", null);
            Log.v("log_tag","url: " + url);

        }

但我得到的结果是非常相关

1 个答案:

答案 0 :(得分:0)

您应该检查ABBY CLOUD OCR SDK。他们有免费试用,所以你可以检查它。