SachinGanesh / screenshot

Flutter Screenshot Library
https://pub.dev/packages/screenshot
MIT License
343 stars 141 forks source link

Uint8List has 0s while taking screenshot on IOS #166

Closed mtalhastar closed 6 months ago

mtalhastar commented 7 months ago

On android its works well but on IOS Uint8List have most of the 0s. This is the function below:  ` Future captureScreenshot() async { late Uint8List? imageBytes; await screenshotController.capture().then((Uint8List? image) { imageBytes = image; print(image.toString()); }).catchError((onError) { print(onError); }); if (imageBytes != null) { final tempDir = await getTemporaryDirectory(); final tempFilePath = '${tempDir.path}/temp_image.png'; final file = await File(tempFilePath).writeAsBytes(imageBytes!);

  final facebytes = await detectAndCropSingleFace(file);
  if (facebytes == null) {
    HomeController.instance.imagesList.clear();
    HomeController.instance.celebrities.clear();
    Get.off(const HomePage(), transition: Transition.fade);
    return;
  }
  HomeController.instance.addImages(facebytes);

  if (counter < celebritiesLength - 1) {
    setState(() {
      counter++;
    });
  } else {
    Get.off(const ResultScreen());
  }
}

} `

OUTPUT: flutter: [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 2, 238, 0, 0, 5, 54, 8, 6, 0, 0, 0, 202, 215, 51, 6, 0, 0, 0, 4, 115, 66, 73, 84, 8, 8, 8, 8, 124, 8, 100, 136, 0, 0, 32, 0, 73, 68, 65, 84, 120, 156, 236, 221, 111, 140, 172, 215, 93, 31, 240, 115, 158, 231, 153, 217, 157, 153, 93, 123, 125, 157, 56, 114, 77, 131, 136, 32, 164, 52, 198, 113, 128, 36, 34, 5, 12, 148, 226, 24, 202, 181, 95, 80, 2, 85, 222, 164, 121, 81, 136, 84, 165, 106, 211, 66, 161, 246, 181, 35, 71, 17, 18, 149, 32, 2, 57, 10, 81, 8, 188, 104, 105, 171, 86, 117, 75, 84, 16, 109, 157, 74, 80, 165, 78, 106, 252, 183, 77, 67, 29, 64, 177, 75, 28, 235, 250, 222, 187, 59, 51, 187, 51, 243, 156, 211, 23, 236, 108, 247, 222, 236, 51, 127, 118, 247, 238, 189, 235, 124, 62, 210, 106, 119, 230, 247, 60, 191, 57, 215, 119, 101, 127, 125, 116, 158, 115, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,<…>

Due to this i am unable to process the screenshot further on IOS.

NeatBee commented 1 month ago

@mtalhastar how did you fix this?

mtalhastar commented 1 month ago

I used InAppWebView instead of WebView and screenshot data started working properly. Always use inappwebview to capture web screen shots.