我在stackoverflow上看到很多答案并尝试了很多可能的组合,但仍然无法获得预期的bllureed图像,如下所示: Side Blur Edges
我试过的代码(使用画布然后覆盖bot图像)
ProxyPreserveHost On
ProxyPass / http://www.example.com:8080/
ProxyPassReverse / http://www.example.com:8080/
使用此代码未获得所需的模糊尝试了几种组合,但仍然没有成功。
答案 0 :(得分:0)
当试图模糊ImageView的两面时,我使用了以下代码:
private void applyBlur(final ImageView image) {
image.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
image.getViewTreeObserver().removeOnPreDrawListener(this);
image.buildDrawingCache();
Bitmap bmp = image.getDrawingCache();
blur(bmp, image);
return true;
}
});
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void blur(Bitmap mBitmap, View view) {
long startMs = System.currentTimeMillis();
float radius = 20;
Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth()),
(int) (view.getMeasuredHeight()), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(overlay);
canvas.translate(-view.getLeft(), -view.getTop());
canvas.drawBitmap(mBitmap, 100, 0,null);
canvas.drawBitmap(mBitmap, -100, 0,null);
RenderScript rs = RenderScript.create(getApplicationContext());
Allocation overlayAlloc = Allocation.createFromBitmap(
rs, overlay);
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(
rs, overlayAlloc.getElement());
blur.setInput(overlayAlloc);
blur.setRadius(radius);
blur.forEach(overlayAlloc);
overlayAlloc.copyTo(overlay);
view.setBackground(new BitmapDrawable(
getResources(), overlay));
rs.destroy();
}//end blur
使ImageView的两侧而不是仅左侧模糊的关键
将canvas.drawBitmap
中的第二个参数更改为负值
例如100变为-100
因此,在canvas.drawBitmap(mBitmap, 100, 0,null);
之后,您添加了canvas.drawBitmap(mBitmap, -100, 0,null);
希望这会有所帮助。