我正在尝试通过将位图转换为字节数组,然后将字节数组转换为 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);
}
但是我得到的结果完全不相关