从OCR提取中,我得到带有边界框的文本的结果,边界框将类似于“ Rect(185,572-254,585)”
private void createPDFDocument(int width, int height) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
PdfDocument pdfDocument = new PdfDocument();
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(width, height, 1).create();
PdfDocument.Page page = pdfDocument.startPage(pageInfo);
Canvas canvas = page.getCanvas();
allCollection = new ArrayList<RecognizedTextEntity>();
for (RecognizedTextEntity textEntity : allCollection) {
textEntity.getRect();
RectF rect = new RectF(textEntity.getRect());
canvas.drawText(textEntity.getTextValue(),canvas.translate(rect,x,y,paint););
}
Paint paint = new Paint();
paint.setColor(Color.parseColor("#ffffff"));
canvas.drawPaint(paint);
pdfDocument.finishPage(page);
SavePDFtoInternalMemory(pdfDocument);
}
}
上面的代码canvas.drawText包含文本,x值和y值,但是我在rect中有四个点; 如何将四点矩形转换为两点以便可以将其添加到画布。