问题
I use blur effect,while applying to bitmap loaded from resources it works as expected,while using universal-imageloader to download image and applying to bitmap it causes A/libc﹕ Fatal signal 7 (SIGBUS), code 2, fault addr 0x9d56e000 in tid 31955 (AsyncTask #1)
public class MyActivity extends ActionBarActivity {
private ImageView ivBackground;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
ivBackground = (ImageView) findViewById(R.id.iv_background);
String imageUri = "https://upload.wikimedia.org/wikipedia/commons/c/c2/Macau-bus-1032.jpg";
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(this));
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showImageForEmptyUri(Color.TRANSPARENT)
.showImageOnFail(Color.TRANSPARENT)
.resetViewBeforeLoading(true)
.cacheOnDisk(true)
.cacheInMemory(false)
.bitmapConfig(Bitmap.Config.RGB_565)
.considerExifParams(true)
.displayer(new FadeInBitmapDisplayer(300))
.build();
imageLoader.displayImage(imageUri, ivBackground, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(final String imageUri, View view, final Bitmap loadedImage) {
Bitmap bmpTest = BitmapFactory.decodeResource(getResources(), R.drawable.test);
//final Bitmap cropedBitmap = Bitmap.createBitmap(bmpTest, 0, 0, bmpTest.getWidth() / 2, bmpTest.getHeight());
final Bitmap cropedBitmap = Bitmap.createBitmap(loadedImage, 0, 0, loadedImage.getWidth() / 2, loadedImage.getHeight());
ivBackground.setImageBitmap(cropedBitmap);
new AsyncTask<Void, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(Void... params) {
Bitmap bitmap = ((BitmapDrawable) ivBackground.getDrawable()).getBitmap();
return blurBitmap(bitmap);
}
@Override
protected void onPostExecute(Bitmap aVoid) {
ivBackground.setImageBitmap(aVoid);
}
}.execute();
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
}
});
}
private Bitmap blurBitmap(Bitmap bitmap) {
Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
RenderScript rs = RenderScript.create(MyActivity.this);
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;
}
}
来源:https://stackoverflow.com/questions/31495455/android-using-renderscript-for-blur-effect-crashes-causes-a-libc-fatal-signal-7