问题是该库检测bitmap
您通过的原件上的单词(以其原始宽度和高度),然后根据该图像返回单词的位置。但屏幕上显示的图像是 SCALED 图像,具有新的宽度和高度以适合屏幕或imageView
. 所以你想要做的是,bitmap
根据你的重新调整imageView
然后通过新的bitmap
//get the scaled bitmap image with the new width and height showed on the screen
private Bitmap getScaledBitmap (Bitmap bitmapImage){
//width and height of original image
final int imageWidth = bitmapImage.getWidth();
final int imageHeight = bitmapImage.getHeight();
//width and height of the imageView
final int imageViewWidth = mImageView.getMeasuredWidth();
final int imageViewHeight = mImageView.getMeasuredHeight();
final int scaledWidth , scaledHeight;
if (imageWidth*imageViewHeight <= imageHeight*imageViewWidth) {
//rescaled width and height of image within ImageView
scaledWidth = (imageWidth*imageViewHeight)/imageHeight;
scaledHeight = imageViewHeight;
}
else {
//rescaled width and height of image within ImageView
scaledWidth = imageViewWidth;
scaledHeight = (imageHeight*imageViewWidth)/imageWidth;
}
return Bitmap.createScaledBitmap(bitmapImage, scaledWidth, scaledHeight, true);
}
我用这个答案来缩放图像:https ://stackoverflow.com/a/13318469/9242141
编辑:抱歉,我注意到您没有在代码中使用位图,并且您的情况可能会有所不同,但我认为您可以根据这个想法找到解决方案,因为我遇到了与您相同的问题并且这有效非常适合我。