2017-09-20 12 views
0

ぼかし画像にRenderScriptを試してみました。 RenderScriptを使ってイメージの一部をぼかす方法を知りたい。私は、コードの下にしようとしたが、それはうまくいきませんでした:画像のぼかし部分

Bitmap overlay = Bitmap.createBitmap(
      mWidth, 
      mHeight, 
      Bitmap.Config.ARGB_8888); 

    Canvas canvas = new Canvas(overlay); 

    canvas.drawBitmap(bitmap, -mletf, 
      -mTop, null); 

    RenderScript rs = RenderScript.create(mContext); 

    Allocation overlayAlloc = Allocation.createFromBitmap(
      rs, overlay); 

    ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(
      rs, overlayAlloc.getElement()); 

    blur.setInput(overlayAlloc); 

    blur.setRadius(mRadius); 

    blur.forEach(overlayAlloc); 

    overlayAlloc.copyTo(overlay); 




    rs.destroy(); 
    return overlay; 

変数mHeightmWidthがぼやけることが高さと一部の幅であり、そのmTopぼかしを開始すべきところ、mletfです。

+0

が重複する可能性が。 Androidアプリケーション](https://stackoverflow.com/questions/18188079/blur-on-touch-android-application) – Tharkius

答えて

-1

使用このライブラリenter link description here

そして

defaultConfig { 
applicationId "com.javatechig" 
minSdkVersion 14 
targetSdkVersion 23 
versionCode 1 
versionName "1.0" 

// Add the following two lines 
renderscriptTargetApi 18 
renderscriptSupportModeEnabled true 

}

次のコードスニペットは、のrenderScriptのAPIを使用してAndroidのビットマップのぼかし効果を作成することができます。

//Set the radius of the Blur. Supported range 0 < radius <= 25 
private static final float BLUR_RADIUS = 25f; 

public Bitmap blur(Bitmap image) { 
    if (null == image) return null; 

    Bitmap outputBitmap = Bitmap.createBitmap(image); 
    final RenderScript renderScript = RenderScript.create(this); 
    Allocation tmpIn = Allocation.createFromBitmap(renderScript, image); 
    Allocation tmpOut = Allocation.createFromBitmap(renderScript, outputBitmap); 

    //Intrinsic Gausian blur filter 
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript)); 
    theIntrinsic.setRadius(BLUR_RADIUS); 
    theIntrinsic.setInput(tmpIn); 
    theIntrinsic.forEach(tmpOut); 
    tmpOut.copyTo(outputBitmap); 
    return outputBitmap; 
} 

上記のコードスニペットを使用して、ImageViewを次のようにぼかすことができます。

ImageView imageView = (ImageView) findViewById(R.id.imageView); 
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.nature); 
Bitmap blurredBitmap = blur(bitmap); 
imageView.setImageBitmap(blurredBitmap); 

enter link description here

0

LaunchOptionsのAPIを使用し、このリンクに従ってください:タッチの[ぼかしの

LaunchOptions lo = new LaunchOptions(); 
lo.setX(mLeft, mLeft+mWidth); 
lo.setY(mTop, mTop+mHeight); 

blur.forEach(overlayAlloc, lo); 
関連する問題