简体   繁体   English

Android:Renderscript错误-无法从位图更新分配,大小不匹配

[英]Android: Renderscript error - Cannot update allocation from bitmap, sizes mismatch

I'm trying to load a photo from the web and perform a blur on it, outputting the blurred image as a separate bitmap. 我正在尝试从网上加载照片并对其进行模糊处理,将模糊的图像输出为单独的位图。 My code looks like this: 我的代码如下所示:

            URL url = new URL(myUrl);
            mNormalImage = BitmapFactory.decodeStream(url.openStream());

            final RenderScript rs = RenderScript.create( mContext );
            final Allocation input = Allocation.createFromBitmap( rs, mNormalImage, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT );
            final Allocation output = Allocation.createTyped( rs, input.getType() );
            final ScriptIntrinsicBlur script;
            script = ScriptIntrinsicBlur.create( rs, Element.U8_4( rs ) );
            script.setRadius( 3.f );
            script.setInput( input );
            script.forEach( output );
            output.copyTo( mBlurredImage );

and I'm getting the error: 我得到了错误:

android.renderscript.RSIllegalArgumentException: 
Cannot update allocation from bitmap, sizes mismatch

Why is this happening? 为什么会这样呢?

Where is mBlurredImage created? mBlurredImage在哪里创建? This is happening because the size of that bitmap doesn't match the input. 发生这种情况是因为该位图的大小与输入不匹配。 You should create it using something like: 您应该使用类似以下的方式创建它:

Bitmap mBlurredImage = 
    Bitmap.createBitmap(
        mNormalImage.getWidth(),
        mNormalImage.getHeight(),
        mNormalImage.getConfig());

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

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