2016-08-29 7 views
0

でステータスバー下のホワイトスペース私はSOの周りのどこかから取得するには、コードのこの部分を使用しています:アンドロイド - スクリーンショット

private static Bitmap getScreenshot(View v) { 
    Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); 
    Canvas c = new Canvas(b); 
    v.draw(c); 
    /*v.setDrawingCacheEnabled(true); 
    Bitmap bitmap = Bitmap.createBitmap(v.getDrawingCache()); 
    v.setDrawingCacheEnabled(false);*/ 
    return b; 
} 

ビューのスクリーンショットを取得します。それは画面全体を取得しますが、Toolbar上記StatusBarの高さの余分な空白で、私はそれを行う getWindow().getDecorView().getRootView()

毎回:これは私が活動のビューを取得する方法です。私はここで失われている、私が提供してはならない余分な情報について私に尋ねてください。

EDIT:

public static Bitmap blur(Context ctx, Bitmap image) { 
    final float BITMAP_SCALE = 0.4f; 
    final float BLUR_RADIUS = 7.5f; 
    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(ctx); 
    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; 
} 

そしてActivityに呼び出されるメソッド::私は忘れてしまった 、私はぼかしの組み合わせて使用​​ここで

public static Bitmap blur(View v) { 
    return blur(v.getContext(), getScreenshot(v)); 
} 

は、ウィンドウのSSです

Blank White Space on top

+0

私はスクリーンショットを表示することができますか?2つを作成Bitmaps? –

+0

私はスクリーンショットを掲示しました....私は突然明瞭さを得ました。私はすぐに答えを投稿するつもりです –

答えて

1

コード私は私の質問は笑再読み込み答えを得た

DisplayMetrics dm = new DisplayMetrics(); 
     ((Activity) this.getContext()).getWindowManager().getDefaultDisplay().getMetrics(dm); 

    android.view.ViewGroup.LayoutParams params = layout.getLayoutParams(); 
    int width = params.width; 
    int height = params.height; 

    Rect rectangle = new Rect(); 
    Window window = ((Activity) RatioImageAd.this.getContext()).getWindow(); 
    window.getDecorView().getWindowVisibleDisplayFrame(rectangle); 

    float imageProportion = (float) width/(float) height; 
    // Get the width of the screen 
    int screenWidth = dm.widthPixels; 
    int screenHeight = window.findViewById(Window.ID_ANDROID_CONTENT).getHeight() - window.findViewById(Window.ID_ANDROID_CONTENT).getPaddingTop(); 
    float screenProportion = (float) screenWidth/(float) screenHeight; 

    if (imageProportion > screenProportion) { 
     params.width = screenWidth; 
     params.height = (int) ((float) screenWidth/imageProportion); 
    } else { 
     params.width = (int) (imageProportion * (float) screenHeight); 
     params.height = screenHeight; 
    } 
    layout.setLayoutParams(params); 
} 

以下のあたりとあなたの関数でビューとして

+0

私はしたし、 'フラグメント'はスクリーンショットを取得しなかった、私は答えを掲載したが改善が必要です私が投稿した答え。 –

+0

私の更新を参照してください100% –

+0

はい、それは取るべきウィンドウの部分を確認することができるはずですが、私は突然笑を持って自分自身のソリューションを使用しています –

0

layoutを渡すように、私ははい、それはStatusBarと同じ高さであることを特徴としますか?そして私は、私はこれを持ってどこかに私のUtilitiesクラスで思い出した:

private static Bitmap getScreenshot(View v) { 
    /*Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight() - getStatusBarHeight(v.getContext()), Bitmap.Config.ARGB_8888); 
    Canvas c = new Canvas(b); 
    v.draw(c);*/ 
    v.setDrawingCacheEnabled(true); 
    Bitmap b = Bitmap.createBitmap(v.getDrawingCache()); 
    Bitmap bb = Bitmap.createBitmap(b, 0, getStatusBarHeight(v.getContext()), b.getWidth(), b.getHeight() - getStatusBarHeight(v.getContext()), null, true); 
    v.setDrawingCacheEnabled(false); 
    return bb; 
} 

コードを改善する上の任意のアイデアを:

public static int getStatusBarHeight(Context context){ 
    int result = 0; 
    int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen" , "android"); 
    if(resourceId > 0){ 
     result = context.getResources().getDimensionPixelSize(resourceId); 
    } 
    return result; 
} 

だから私は、私の中にぼかしを編集しますか?

関連する問題