이보십시오.
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);
}
저장 디렉터리에 이미지를 저장 한 다음 해당 이미지를 이미지보기로 설정하십시오. –
내 대답을 참조하십시오 선생님, 이것이 당신을 도울 것입니다. –