我正在尝试使用renderscript执行以下操作: -将图像从YUV转换为灰度(在我的代码中称为root的脚本) -做一些图像处理 -输出最终图像(在我的代码中称为输出的脚本) 我能够做到第一步。但是,当我要输出最终图像时(稍后将进行图像处理),该代码不想编译。 这是我的renderScript代码:
using (PaintingDB DB = new PaintingDB()) {
int YearOfWork = 0;
int.TryParse(ddlYear.SelectedValue, out Year);
// ireader
trPaintings.DataSource = DB.Museums_GetPaintings(Musea.ID);
// ? trPainting.Comparer = new DataReaderComparer("year",DataReaderType.Integer);
trPaintings.DataBind()
我的Java代码:
uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
oldX = x;
oldY = y;
x*=3;
y*=3;
if (x < 480) {
x += 2*(479-x);
} else {
x -= 2*(x-479);
}
pos = 0;
yValue = 0;
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
index[pos] = (x+i) * height + (y+j);
yValue += (float) rsGetElementAt_uchar(yuvIn, index[pos]);
pos += 1;
}
}
yValue = (float) yValue / pos;
tImgIndex = oldX * 426 + oldY;
if (yValue > thresholdValue || y == 426*3) {
out = (uchar4) {255, 255, 255, 255};
tImg[tImgIndex] = 1;
} else {
out = (uchar4) {0, 0, 0, 255};
tImg[tImgIndex] = 0;
}
return out;
//rsDebug("called root", rsUptimeMillis());
}
uchar4 __attribute__((kernel)) output(uint32_t x, uint32_t y) {
out = (uchar4) {0, 0, 0, 255};
if (tImg[x*426+y] == 0) {
out = (uchar4) {0, 0, 0, 255};
} else if (tImg[x*426+y] == 1){
out = (uchar4) {255, 255, 255, 255};
} else {
out = (uchar4) {0, 255, 0, 255};
}
return out;
//rsDebug("called root", rsUptimeMillis());
}