如何将模糊效果应用于universal-image-loader的onLoadingComplete中的位图?

时间:2015-07-17 21:34:19

标签: android bitmap universal-image-loader renderscript

我需要将模糊效果应用于通过universal-imageloader下载的位图 但崩溃和日志中我得到了这样的信息:

// 4508-4564 / com.sample A / libc:致命信号7(SIGBUS),代码2,故障地址0x9c4e9000 in tid 4564(com.sample) // 07-18 19:49:20.019 4508-4570 / com.sample A / libc:致命信号7(SIGBUS),代码2,故障地址0x9c4e9000 in tid 4570(com.sample) // 07-18 19:49:20.019 4508-4569 / com.sample A / libc:致命信号7(SIGBUS),代码2,故障地址0x9c4e9000 in tid 4569(com.sample) // 07-18 19:49:20.019 4508-4565 / com.sample A / libc:致命信号7(SIGBUS),代码2,故障地址0x9c4e9000 in tid 4565(com.sample)

ImageLoader imageLoader = ImageLoaderInstances.initGeneralImageLoader();
imageLoader.loadImage(fileName,new SimpleImageLoadingListener(){
    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
cropedBitmap = Bitmap.createBitmap(loadedImage, 0, 0, loadedImage.getWidth() / 2, loadedImage.getHeight());
        imageView.setImageBitmap(blurBitmap(cropedBitmap));
    }
});



   private Bitmap blurBitmap(Bitmap bitmap) {
    Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    RenderScript rs = RenderScript.create(getContext());
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
    Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);
    blurScript.setRadius(25.f);
    blurScript.setInput(allIn);
    blurScript.forEach(allOut);
    allOut.copyTo(outBitmap);
    bitmap.recycle();
    rs.destroy();
    return outBitmap;
}

1 个答案:

答案 0 :(得分:0)

添加一些日志记录来验证,或者使用调试器,但我认为崩溃很可能发生在这一行:

output.copyTo(blurredBitmap);

创建blurredBitmap时,输入位图的宽度和高度的1/10。它的Allocation是输入位图的完整大小。