簡體   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