0

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?

Jon
  • 7,941
  • 9
  • 53
  • 105

1 Answers1

3

Where is mBlurredImage created? 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());
Larry Schiefer
  • 15,687
  • 2
  • 27
  • 33
  • 1
    +1 for this answer. The error happens in "output.copyTo( mBlurredImage );" and it shows that the dimensions of mBlurredImage does not match Allocation output. Also, it is better to use "createFromBitmap( rs, mNormalImage )" to create the input Allocation. In this way, it will actually use a optimized creation without extra copy of the bitmap data. – Miao Wang May 25 '16 at 04:07