繁体   English   中英

使用Android Renderscript添加2张图片

[英]Adding 2 Images with Android Renderscript

我试图通过增加2背对背拍摄的值来增加相机的曝光时间。 使用Java进行计算花了太长时间,因此我决定尝试使用Renderscript。 我似乎已经解决了所有错误,但最终结果产生了一些非常奇怪的效果 图像变蓝和变绿

此图像中的大多数椅子和地板都很好,但大部分区域会出现鲜绿色和蓝色变色。

这是Renderscript文件:

#pragma version(1)
#pragma rs java_package_name(edu.marquette.mcw.smartme)

rs_allocation extra_alloc;

uchar4 __attribute__((kernel)) combine(uchar4 a, uint32_t x, uint32_t y)
{
    // get second image
    uchar4 b = rsGetElementAt_uchar4(extra_alloc, x, y);

    // combine red value
    uint32_t red = a.r + b.r;
    //set to max value if it exceeds it
    if(255 - a.r < b.r)
    {
        red = 255;
    }
    a.r = red;

    // combine green value
    uint32_t green = a.g + b.g;
    if(255 - a.g < b.g)
    {
        green = 255;
    }
    a.g = green;

    // combine blue value
    uint32_t blue = a.b + b.b;
    if(255 - a.b < b.b)
    {
        blue = 255;
    }
    a.b = blue;

    // return result
    return a;
}

这是执行Renderscript的Java代码:

// Load Script
RenderScript RS = RenderScript.create(callingFrag.getActivity());
ScriptC_combine script = new ScriptC_combine(RS);

output = Bitmap.createBitmap(combined.getWidth(), combined.getHeight(), combined.getConfig());

// Send in bitmaps
Allocation aAllocation = Allocation.createFromBitmap(RS, combined);
Allocation bAllocation = Allocation.createFromBitmap(RS, exposures.remove(0));
Allocation outputAllocation = Allocation.createFromBitmap(RS, output);
script.set_extra_alloc(bAllocation);

// Run Script
script.forEach_combine(aAllocation, outputAllocation);
App.log("Combine Time: " + (System.currentTimeMillis() - start));
outputAllocation.copyTo(output);

我在日志中找不到任何似乎是警告/错误的内容。 关于如何解决的任何想法?

最终,我找到了一个库,该库完全可以满足我的需求,并且仅用大约1行就可以覆盖更多内容。

easyRS可以让我将2张图像合并为:

Blend.add(rs, inputBitmap, inputBitmap2);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM