how i can print screen a single part of my layout?

João Armando

thank you in advance for your attention.

I need a print screen in only one part of my layout and not in it all. For example, below I have 2 cardViews, one of them is just a random cardview, I would like to save only one image of the second cardView, which contains the text "I want to print screen just this CardView", only it, and not all the rest Objects in the layout.

image Example here

I have no idea how to do this. Has anyone ever faced the same difficulty or know how I can do it? thank you again.

Andy Developer

Try this.

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

Now just pass the card to captureScreenShot(). It returns the bitmap and save that bitmap saveImage().

You can pass any view Like RelativeLayout, LinearLayout etc any view can pass to 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();
    }
}

Finally call this function like this.

saveImage(captureScreenShot(card));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I make part of my page always be in the same position relative to the screen?

From Dev

How can I print-screen just one window and not my entire desktop?

From Dev

How can I print-screen just one window and not my entire desktop?

From Dev

How can I take a screenshot in LXDE using scrot and the Print Screen button on my keyboard?

From Dev

How can i print numbers on single line

From Dev

How can I add a EULA screen to my MacOS single bundle archive with Install4J?

From Dev

How can I fix my keyboard layout?

From Dev

How can I fix my keyboard layout?

From Dev

How can I improve my android layout

From Dev

How can I record my screen?

From Dev

How can i center these images on my screen

From Dev

How can I increase my screen resolution?

From Dev

How can I record my screen?

From Dev

How can I print my outcome as a list?

From Dev

How can I print my outcome as a list?

From Dev

How can I landscape my laptop screen, with a LCD screen

From Dev

How can I make screenshot of the part of the screen with ImageMagick?

From Dev

How can I disable a part of the screen in X.Org

From Dev

How can I create HUD (mirrored) layout/screen Android?

From Dev

How can I create a two column per page print layout?

From Dev

How can i add my layout to my gallery?

From Dev

How can i print json file that is produced from ParseHub on screen?

From Dev

My content leaves my screen, how can I prevent this?

From Dev

How can I truncate ${level} in nlog layout to a single character?

From Dev

How can i print my array and my histogram on the same line?

From Dev

How can I print multiple outcomes of the same records in a single row?

From Dev

How can I print all the elements of a vector in a single string in R?

From Dev

How can I print a single row element in Python DictReader

From Dev

How can I print multiple outcomes of the same records in a single row?

Related Related

  1. 1

    How can I make part of my page always be in the same position relative to the screen?

  2. 2

    How can I print-screen just one window and not my entire desktop?

  3. 3

    How can I print-screen just one window and not my entire desktop?

  4. 4

    How can I take a screenshot in LXDE using scrot and the Print Screen button on my keyboard?

  5. 5

    How can i print numbers on single line

  6. 6

    How can I add a EULA screen to my MacOS single bundle archive with Install4J?

  7. 7

    How can I fix my keyboard layout?

  8. 8

    How can I fix my keyboard layout?

  9. 9

    How can I improve my android layout

  10. 10

    How can I record my screen?

  11. 11

    How can i center these images on my screen

  12. 12

    How can I increase my screen resolution?

  13. 13

    How can I record my screen?

  14. 14

    How can I print my outcome as a list?

  15. 15

    How can I print my outcome as a list?

  16. 16

    How can I landscape my laptop screen, with a LCD screen

  17. 17

    How can I make screenshot of the part of the screen with ImageMagick?

  18. 18

    How can I disable a part of the screen in X.Org

  19. 19

    How can I create HUD (mirrored) layout/screen Android?

  20. 20

    How can I create a two column per page print layout?

  21. 21

    How can i add my layout to my gallery?

  22. 22

    How can i print json file that is produced from ParseHub on screen?

  23. 23

    My content leaves my screen, how can I prevent this?

  24. 24

    How can I truncate ${level} in nlog layout to a single character?

  25. 25

    How can i print my array and my histogram on the same line?

  26. 26

    How can I print multiple outcomes of the same records in a single row?

  27. 27

    How can I print all the elements of a vector in a single string in R?

  28. 28

    How can I print a single row element in Python DictReader

  29. 29

    How can I print multiple outcomes of the same records in a single row?

HotTag

Archive