我想创建一个类似于Instagram Tilt Shift(径向/线性)的动画,我试图从现有图像创建一个模糊的位图,并在动画开始和停止时更改imageView源。但它缓慢且不顺畅。
public class BlurMaskHandler extends AsyncTask<Integer,Integer,Bitmap> {
@Override
protected Bitmap doInBackground(Integer... drawable) {
Bitmap bitmapMaster = BitmapFactory.decodeResource(getResources(), drawable[0]);
int w = bitmapMaster.getWidth();
int h = bitmapMaster.getHeight();
RectF rectF = new RectF(0,0,w,h);
float blurRadius = 500.0f;
Bitmap bitmapResult = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvasResult = new Canvas(bitmapResult);
Paint blurPaintOuter = new Paint();
blurPaintOuter.setColor(0xFFffffff);
blurPaintOuter.setMaskFilter(new
BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.INNER));
canvasResult.drawBitmap(bitmapMaster, 0, 0, blurPaintOuter);
Paint blurPaintInner = new Paint();
blurPaintInner.setColor(0x80ffffff);
blurPaintInner.setMaskFilter(new
BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.INNER));
canvasResult.drawRect(rectF, blurPaintInner);
return bitmapResult;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
bitmapView = bitmap;
}
}