如何以编程方式在 react-native 中截取屏幕截图

如何以编程方式在 react-native 中截取屏幕截图

问题描述:

如何在 ReactNative 中截取屏幕截图.我需要一个屏幕截图并将其放在 Image 组件中.我该怎么办?

How can I take a screenshot in ReactNative. I need a screenshot and put it in Image component. How could I do?

有一个库可以做到这一点:React Native View Shot

There is a library to do just that: React Native View Shot

import RNViewShot from "react-native-view-shot";

RNViewShot.takeSnapshot(viewRef, {
  format: "jpeg",
  quality: 0.8
})
.then(
  uri => console.log("Image saved to", uri),
  error => console.error("Oops, snapshot failed", error)
);