android - RenderScript acting weird and returning nothing -


i'm using renderscript , when write kernel, @ first acting ok. when change kernel , rebuild project returns nothing. knows why? return blank photo , nothing else.

i have fixed it. problem me targetsdkversion 24 . found out in android 7, there has been lot of changes (new features) renderscript, have changed targetsdkversion 22 , fixed issue. tried simple filter, , after using filter showed me nothing in imageview. when changed targetsdkversion 22 fixed problem , see filtered image in imageview. here code i've used:

uchar4 __attribute__((kernel)) filtered(uchar4 in, uint32_t x, uint32_t y) {  uchar4 out = in;  out.r = 255 - in.r;  out.g = 255 - in.g;  out.b = 255 - in.b;  return out; } 

if interested can try targetsdkversion 24 , 22. , here code java part:

public void imagefilter(bitmap bmp) {      doallocation();      operationbitmap = bitmap.createbitmap(bmp.getwidth(),             bmp.getheight(), bmp.getconfig());      int height = operationbitmap.getheight();     int width = operationbitmap.getwidth();      toast.maketext(mainactivity.this, width + " x " + height, toast.length_short).show();      scriptc_cnn cnnscript = new scriptc_cnn(rs);     cnnscript.foreach_filtered(allocin, allocout);      allocout.copyto(operationbitmap);     selectedimagepreview.setimagebitmap(operationbitmap);     rs.destroy(); }  public void doallocation() {          allocin = allocation.createfrombitmap(rs, originalbitmap,                 allocation.mipmapcontrol.mipmap_none,                 allocation.usage_script);          allocout = allocation.createtyped(rs,                 allocin.gettype()); } 

and can see renewed document of google in developer.android website. here link: https://developer.android.com/guide/topics/renderscript/compute.html#writing-an-rs-kernel

you can see mapping kernel can use rs_kernel instead of attribute((kernel)). , google mentioned rs_kernel macro defined automatically renderscript convenience:

#define rs_kernel __attribute__((kernel)) 

update here gradle:

android { compilesdkversion 24 buildtoolsversion "24.0.1"  defaultconfig {     applicationid "shahryar.com.cellularneuralnetwork"     minsdkversion 16     targetsdkversion 22     versioncode 1     versionname "1.0"     renderscriptsupportmodeenabled true;     renderscripttargetapi 16; } buildtypes {     release {         minifyenabled false         proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro'     } } }  dependencies { compile filetree(dir: 'libs', include: ['*.jar']) testcompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:24.2.0' } 

and have used renderscripttargetapi 16 according line in google's document: valid values setting integer value 11 released api level. if minimum sdk version specified in application manifest set different value, value ignored , target value in build file used set minimum sdk version.

note: gradle version working me.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -