我有一张图片作为资源,我需要通过 OpenCV 对其进行修改,然后我想将我的新图片放在原始 ImageView 中。
我试过这种方式,但是:
public class VerifianceActivity extends Activity {
/** Called when the activity is first created. */
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
if (status == LoaderCallbackInterface.SUCCESS ) {
// now we can call opencv code !
Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.cmc7);
Mat myMat = new Mat();
Utils.bitmapToMat(mBitmap, myMat);
Imgproc.cvtColor(myMat, myMat, Imgproc.COLOR_BGR2GRAY);
Utils.matToBitmap(myMat, mBitmap);
ImageView mIV = (ImageView) findViewById(R.id.imageView);
mIV.setImageBitmap(mBitmap);//NPE
//this line is suppose to work, but the app crashes.
setContentView(R.layout.main);
} else {
super.onManagerConnected(status);
}
}
};
@Override
public void onResume() {;
super.onResume();
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_5,this, mLoaderCallback);
// you may be tempted, to do something here, but it's *async*, and may take some time,
// so any opencv call here will lead to unresolved native errors.
}
}
有什么建议吗?我收到 NullPointerException 作为错误