我正在将一个Image(Drawable)加载到Mat中,然后将其转换为ImageView的Bitmap。
private void setupImageView() {
originalImage = new Mat();
workingImage = new Mat();
mask = new Mat();
// Load Drawable into Mat
try {
originalImage = Utils.loadResource(this, R.drawable.image, Imgcodecs.CV_LOAD_IMAGE_UNCHANGED);
} catch (IOException e) {
e.printStackTrace();
}
// Convert for needed 3 channels
Imgproc.cvtColor(originalImage, workingImage, Imgproc.COLOR_RGB2BGR);
// Convert Mat to Bitmap for ImageView
Bitmap bm = Bitmap.createBitmap(workingImage.cols(), workingImage.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(workingImage, bm);
imageView.setImageBitmap(bm);
// Create a new Mat Object
// Mask should be 2 pixels wider and 2 pixels taller than the originalImage
mask.create(workingImage.rows() + 2, workingImage.cols() + 2, CV_8UC1);
}
在ImageView内部单击时,无法识别单击,因为它们位于填充算法的Mat对象之外。
@OnTouch(R.id.imageview)
boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Point seed = new Point(event.getX(), event.getY());
....
}
return true;
}
为什么Mat和ImageView的高度和宽度不同? 我需要更改什么,我的点击是否已注册?