2017-09-14 12 views
1

スクリーンショットのアクティビティのレイアウトで影や仰角をキャプチャする方法。このコードは、ビューのスクリーンショットを取るが、ここでの眺めの画像の説明をシャドウしていない。Androidスクリーンショットの影をキャプチャする方法

View screenView = parentMain; 
    screenView.buildDrawingCache(); 
    screenView.setDrawingCacheEnabled(true); 
    Bitmap bitmap = Bitmap.createBitmap(screenView.getWidth() , screenView.getHeight(), Bitmap.Config.ARGB_8888); 
    Canvas c = new Canvas(bitmap); 
    screenView.layout(0, 0, screenView.getLayoutParams().width, screenView.getLayoutParams().height); 
    screenView.draw(c); 
    screenView.setDrawingCacheEnabled(false); 
    fakeImgView.setImageBitmap(bitmap); 

enter image description here

結果

enter image description here

+0

イメージをストレージディレクトリに保存し、そのイメージをイメージビューに設定してください。 –

+0

私の答えを参照してくださいこれはあなたを助けてくれるはずです。 –

答えて

1

これを試してみてください。

CardView card = (CardView) findViewById(R.id.card); 

これで、カードをcaptureScreenShot()に渡します。ビットマップを返し、そのビットマップsaveImage()を保存します。

任意のビューをRelativeLayout、LinearLayoutなどと同様に渡すことができます。ビューは、captureScreenShot()に渡すことができます。

// Function which capture Screenshot 
public Bitmap captureScreenShot(View view) { 
    /* 
    * Creating a Bitmap of view with ARGB_4444. 
    * */ 
    Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_4444); 
    Canvas canvas = new Canvas(bitmap); 
    Drawable backgroundDrawable = view.getBackground(); 

    if (backgroundDrawable != null) { 
     backgroundDrawable.draw(canvas); 
    } else { 
     canvas.drawColor(Color.parseColor("#80000000")); 
    } 
    view.draw(canvas); 
    return bitmap; 
} 

// Function which Save image. 
private void saveImage(Bitmap bitmap) { 
    File file = // Your Storage directory name + your filename 
    if (file == null) { 
     return; 
    } 
    try { 
     FileOutputStream fos = new FileOutputStream(file); 
     bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); 
     fos.close(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

最後に、このようにこの関数を呼び出します。

saveImage(captureScreenShot(card)); 

このように画像を設定します。

File file = new File(“yourImageFilePath”); 
if(file.exists()) 
{ 
    yourImageView.setImageURI(Uri.fromFile(file)); 
} 

注:setImageURI()が機能しない場合は、以下のコードを使用できます。

File file = new File(“yourImageFilePath”); 
if(file.exists()) 
{ 
    Bitmap bitmap = BitmapFactory.decodeFile(file.toString()); 
    yourImageView.setImageBitmap(bitmap); 
} 
+0

が機能しませんでした:/ –

関連する問題