how to take screenshot of specific area on the screen in flutter?

672

well i don't know about x and y but what you can do is screen shot of specific widgets with package screenshot, link

this package capture widgets as Images, even if they are not rendered on screen.

Step 1: create a controller

ScreenshotController screenshotController = ScreenshotController();

Step 2: wrap widgets with Screenshot()

Screenshot(
    controller: screenshotController,
    child: Text("This text will be captured as image"),
),

step 3: Take the screenshot by calling capture method. This will return a Uint8List

screenshotController.capture().then((Uint8List image) {
    //Capture Done
    setState(() {
        _imageFile = image;
    });
}).catchError((onError) {
    print(onError);
});
Share:
672
Zain Ur Rehman
Author by

Zain Ur Rehman

Updated on January 02, 2023

Comments

  • Zain Ur Rehman
    Zain Ur Rehman over 1 year

    enter image description here

    I want to extract an image of a specific area on the screen? I have the x, y, height, and width. Anybody knows how can I achieve that?

    • WSBT
      WSBT over 2 years
      Maybe you can take a screenshot with RepaintBoundary and then crop the PNG?