@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.Canny_Edge) //Unfortunately stops the app when we use this option {
ImageView i = (ImageView) findViewById(R.id.image_view);
Bitmap bmp =BitmapFactory.decodeResource(getResources(),R.drawable.smiley);
Mat srcMat = new Mat ( bmp.getHeight(), bmp.getWidth(), CvType.CV_8UC3);
Bitmap myBitmap32 = bmp.copy(Bitmap.Config.ARGB_8888, true);
Utils.bitmapToMat(myBitmap32, srcMat);
Mat gray = new Mat(srcMat.size(), CvType.CV_8UC1);
Imgproc.cvtColor(srcMat, gray, Imgproc.COLOR_RGB2GRAY,4);
Mat edge = new Mat();
Mat dst = new Mat();
Imgproc.Canny(gray, edge, 80, 90);
Imgproc.cvtColor(edge, dst, Imgproc.COLOR_GRAY2RGBA,4);
Bitmap resultBitmap = Bitmap.createBitmap(dst.cols(), dst.rows(),Bitmap.Config.ARGB_8888);
Utils.matToBitmap(dst, resultBitmap);
i.setImageBitmap(resultBitmap);
}
else if(id == R.id.Sobel) {
ImageView i = (ImageView) findViewById(R.id.image_view);
i.setImageResource(R.drawable.apj);
//some code
}
return super.onOptionsItemSelected(item);
}
在上面的代码中,Android Studio 没有显示任何错误。但不幸的是,该应用程序停止获取此Canny_Edge 选项(在菜单中)。为什么,谁能解决这个问题。