我希望能够使用 RenderScript 裁剪图像。这是我的裁剪函数:
uchar4 __attribute__((kernel)) crop(const uchar4 in, uint32_t x, uint32_t y){
int minX = centerX - cropWidth;
int maxX = centerX + cropWidth;
int minY = centerY - cropHeight;
int maxY = centerY + cropHeight;
uchar4 out = in;
if((minX < x < maxX ) && (minY < y < maxY)){
return out;
}
else{
out.r = 0;
out.g = 0;
out.b = 255;
return out;
}
}
这是所需的逻辑:
如果像素不在 IF 条件中指定的 X Y 范围内,那么我希望该像素为蓝色。
出于某种原因,无论我的边界多么严格,没有像素是蓝色的。有人可以向我解释这是为什么吗?又该如何解决呢?
如果我将 IF 条件替换为 false(if(false)
,因此它保证了 ELSE 代码的执行),则所有像素都是蓝色(如预期)。
最佳答案
minX < x < maxX
没有按照您期望的方式工作。该代码所做的首先检查是否 minX < x
,然后将生成的 boolean 值转换为整数(将为 0 或 1),最后检查该整数是否小于 maxX
(它永远都是)。 (同样的事情也发生在 y
上)。您需要重写该检查,例如:
(minX < x && x < maxX ) && (minY < y && y < maxY)
关于java - 如何使用 RenderScript 裁剪图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29066019/