【问题标题】:Is there a way i can download an image with text appended on it with react native有没有办法我可以下载带有文本的图像,并使用本机反应
【发布时间】:2020-09-21 13:02:42
【问题描述】:

我正在构建一个 react-native 应用程序,到目前为止,屏幕将图像从 uri 加载到 BackgroundImage 中,并且图像顶部还加载了一些文本,请参阅附图:

所以我想要的是将这个图像和文本下载到设备上,如果你愿意的话,合并它们?

欢迎任何建议..

谢谢

【问题讨论】:

    标签: image react-native download blob react-native-android


    【解决方案1】:

    我建议您使用来自here 的 ViewShot 组件。

    这是一个如何将它与项目集成的示例(请记住,这使用 ES6 箭头函数语法):

    class CaptureImage extends Component {
      capturePic = () => {
        this.refs.viewShot.capture().then(uri => {
          console.log("Path to the image: ", uri);  // do what you want with the url
        })
      };
    
      render() {
        return (
          <View
            <ViewShot ref="viewShot">
    
              // your background image components go here (the image with the text you want to capture)
    
            </ViewShot>
    
            // rest of your code goes here
    
            <Button onClick= {() => capturePic()} />  // button just for demonstration purpose
          </View>
        );
      }
    }
    

    希望你能理解:)

    【讨论】:

    • 这看起来很适合我的需要,我会告诉你我的进展如何,谢谢
    • 很高兴知道这是您所需要的!
    • 这几乎可以工作了,我能够获取图像上的 base64 字符串,但有没有办法将其转换为 blob 并将其下载到设备上?
    • 要将 base64 字符串保存为图像,请参阅 this 参考。它似乎回答了你的问题。
    • 这回答了你的问题吗?
    猜你喜欢
    • 2021-01-05
    • 1970-01-01
    • 2019-11-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多