Android change image in a ImageView? -
i have picture resource, need modify opencv, put new image in original imageview.
i tried way, :
public class verifianceactivity extends activity { /** called when activity first created. */ private baseloadercallback mloadercallback = new baseloadercallback(this) { @override public void onmanagerconnected(int status) { if (status == loadercallbackinterface.success ) { // 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 suppose work, 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); // may tempted, here, it's *async*, , may take time, // opencv call here lead unresolved native errors. } }
any advice ? got nullpointerexception error
the problem need call
setcontentview(r.layout.main);
before accessing views
or null
such as
imageview miv = (imageview) findviewbyid(r.id.imageview);
since views
exist inside layout
inflate setcontentview()
, don't exist until inflate layout
return null
if try initialize them before inflating layout
Comments
Post a Comment