如何使用本机反应按钮获取屏幕截图?

时间:2017-12-23 11:55:34

标签: reactjs react-native screenshot

我想开发一个简单的应用程序,可以通过按钮截取当前屏幕的截图。此代码成功运行,但是当我按下捕获按钮时,它不起作用并返回错误。



export default class App extends Component<{}> {
  render() {
    captureScreen({
      format: "jpg",
      quality: 0.8
    })
    .then(
      uri => console.log("Image saved to", uri),
      error => console.error("Oops, snapshot failed", error)
    );
    
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native SnapShot!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit App.js
        </Text>
        <Text style={styles.instructions}>
          {instructions}
        </Text>
        <Button
          onPress={captureScreen.bind(this)}
          title="capture"
          color="#841584"
          accessibilityLabel="Capture"
        />
      </View>
    );
  }
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

为什么要在渲染中捕获屏幕截图?我认为您需要将截屏片段移动到单独的功能。

Public Sub CreateView(LookFor As String)
    Dim Conn        As Object
    Dim SQL         As String
    Dim rs          As Object
    Dim outSheet    As Worksheet
    Const adStateOpen = 1

    'The view sheet is where the data will go to
    Set outSheet = ThisWorkbook.Worksheets("View")

    'Field 3 = Column C, Field 4 = Column D
    'If your field has headers use that, otherwise, add headers
    SQL = "Select [Field 3], [Field 4], [Field 18] from [Raw$] Where [Field 3] = '" & LookFor & "'"

    Set Conn = CreateObject("ADODB.Connection")

    'Connect to current spreadsheet
    Conn.connectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.FullName & _
                            ";Extended Properties='Excel 12.0;HDR=YES';"
    Conn.Open

    'Get the recordset
    Set rs = Conn.Execute(SQL)

    'Add the data to the view sheet
    With outSheet
        .Cells.ClearContents
        .Range("A1:C1").Value = Array("Field 1", "Field 3", "Field18")
        .Range("A2").CopyFromRecordset rs
        .Activate
    End With

    'Close the connection if it's open
    If Conn.State = adStateOpen Then Conn.Close
End Sub

Private Sub caller()
    'This is the caller routine
    Application.ScreenUpdating = False
    Dim searchCriteria As String
    searchCriteria = InputBox("Enter the search field", "Enter criteria")
    CreateView (searchCriteria)
    Application.ScreenUpdating = True
End Sub