次のコードを使用して、画像ビューの背景がぼやけています。レンダスクリプトを使用したアンドロイドの問題
public class BlurBuilder {
private static final float BITMAP_SCALE = 0.2f;
private static final float BLUR_RADIUS = 25f;
public static Bitmap blur(Context context, Bitmap image) {
int width = Math.round(image.getWidth() * BITMAP_SCALE);
int height = Math.round(image.getHeight() * BITMAP_SCALE);
Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
RenderScript rs = RenderScript.create(context);
ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
theIntrinsic.setRadius(BLUR_RADIUS);
theIntrinsic.setInput(tmpIn);
theIntrinsic.forEach(tmpOut);
tmpOut.copyTo(outputBitmap);
return outputBitmap;
}
}
ブラーは、ほとんどの時間のために罰金建てが、任意のクラッシュログなしで私のアプリがクラッシュし、最終的に、時間をかけて悪い取得されます。エミュレータ上で実行している時に、私は厳しいテストの後、次のエラーを見てきました:
09-01 15:05:03.230 4624-9758/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83
09-01 15:05:03.238 4624-9781/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83
09-01 15:05:03.242 4624-10128/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83
09-01 15:05:03.242 4624-9610/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83
09-01 15:05:03.242 4624-9781/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83
09-01 15:05:03.250 4624-9767/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83
09-01 15:05:03.254 4624-9758/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83
... (same error - many more times and then crash)
私はこの点でクエリを次ています
私はのrenderScriptに対して次のGradle設定を使用しています:
compileSdkVersion 23 buildToolsVersion "23.0.3"
defaultConfig { applicationId "package" minSdkVersionが19 targetSdkVersion 23 multiDexEnabled真 renderscriptTargetApi 19 renderscriptSupportModeEnabled真 }
のrenderScriptライブラリーの推奨バージョンは何ですか? android.support.v8.renderscript.Allocation or
android.renderscript`パッケージから依存関係をインポートする必要がありますか?
- レンダスクリプトライブラリを使用せずにぼかし効果を達成できますか?
使用しているビルド・ツールのバージョンは何ですか? –
buildToolsVersion "23.0.3" – jay
もう1つの質問ですが、アプリをテストしたデバイスとAndroidのバージョンは何ですか?私はあなたが2つのことを試してみることをお勧めします:1.あなたがそれを作成した後に "rs"と "theIntrinsic"をキャッシュしようとします。 2.最新のBuild-Tools(24.0.1) –