我在使用renderscript,当我编写内核时,起初它的行为正常。但是当我更改内核并重建项目时,它不会返回任何内容。有人知道为什么吗?它只是返回一张空白的照片,没有别的。RenderScript行为怪异并且什么都不返回
0
A
回答
1
我已修复它。对我来说问题是targetSdkVersion 24。我发现,在android 7中,renderscript有很多变化(NEW FEATURES),所以我已经将它改为targetSdkVersion 22,它解决了这个问题。我试图做一个简单的过滤器,使用过滤器后,它没有在imageview中显示任何内容。但是当我将targetSdkVersion更改为22时,它解决了问题,我可以在imageview中看到已过滤的图像。这里是我使用的代码:
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;
}
如果你有兴趣,你可以与targetSdkVersion 24和22,并在这里品尝它为Java的部分代码:
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());
}
,你可以请在developer.android网站上查看更新的google文档。这里是链接: https://developer.android.com/guide/topics/renderscript/compute.html#writing-an-rs-kernel
您可以看到,对于映射内核,您可以使用RS_KERNEL而不是属性((内核))。和谷歌提到RS_KERNEL是的renderScript为了您的方便自动定义一个宏:
#define RS_KERNEL __attribute__((kernel))
UPDATE 这里是我的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'
}
,我已经根据在此行中使用renderscriptTargetApi 16谷歌的文件:此设置的有效值是从11到最近发布的API级别的任何整数值。如果您的应用程序清单中指定的最低SDK版本被设置为不同的值,则该值将被忽略,并且构建文件中的目标值将用于设置最低SDK版本。
注意:这是现在为我工作的gradle版本。
相关问题
- 1. 为什么Ansible跳过主机组并且什么都不做
- 2. Json_decode什么都不返回
- 3. cin.Getline什么都不返回
- 4. href什么都不返回?
- 5. 什么都不返回
- 6. geoip_record_by_name什么都不返回?
- 7. XMLHttpRequest什么都不返回?
- 8. JsonObjectRequest什么都不返回
- 9. MVC的UpdateModel行为奇怪并且还原值。为什么?
- 10. 为什么我的代码停止并且没有返回异常?
- 11. 什么时候empty()返回false并且$ var ==''返回true?
- 12. 为什么find_all BeautifulSoup4函数什么都不返回?
- 13. 为什么这个查询什么都不返回?
- 14. 为什么“Membership.GetUser(strUser)”什么都不返回?
- 15. 为什么FB.UI共享响应什么都不返回?
- 16. 为什么UTTypeCreatePreferredIdentifierForTag返回奇怪的UTI?
- 17. bitcoinrpc调用什么都不会返回
- 18. 函数PDO什么都不返回?
- 19. PhantomJS querySelectorAll()。textcontent什么都不返回
- 20. Request.Form(“ListBox1.ClientID”)什么都不返回
- 21. SimpleXMLElement() - XPath()和SOAP什么都不返回
- 22. Updated_postmeta参数什么都不返回
- 23. GridView1.SelectedRow什么都不返回
- 24. 覆盖sendResetLinkEmail什么都不会返回
- 25. INNER JOIN mysql什么都不返回
- 26. 节点server.js什么都不返回
- 27. 为什么SIGINT发送给子进程并且什么都不做?
- 28. 怪异的回合行为
- 29. 为什么solve.QP返回不可行解
- 30. 在TensorFlow中,为什么tf.train.shuffle_batch会永久挂起,并且不会返回批次?
任何人都可以提供建议或帮助之前,您需要提供更多信息。请参阅[我如何问一个好问题](http://stackoverflow.com/help/how-to-ask)和[如何创建一个最小,完整和可验证的示例](http://stackoverflow.com/help/MCVE)。 –
你可以发布你的源代码,以便我们能够理解它可能会出现什么问题吗? :) – cmaster11
我已修复它。对我来说问题是targetSdkVersion 24。我发现在android 7中,renderscript发生了很多变化,所以我将它改为targetSdkVersion 22并解决了这个问题。代码是来自google文档的示例代码。 @LarrySchiefer – Shahryar