これを試してみてください。
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);
}
イメージをストレージディレクトリに保存し、そのイメージをイメージビューに設定してください。 –
私の答えを参照してくださいこれはあなたを助けてくれるはずです。 –