I need to add a feature on my app that allows users to save, as an image, in their Photo Documents on the device, a portion of the App.
I'm using Nuxt.js and the content is just inside a Dialog, simple like this:
<v-card ref="print" outlined class="certificate">
<v-img :src="photo.url"></v-img>
<v-card-text>
{{ photo.title }}
</v-card-text>
</v-card>
The image src is on external storage, not in my assets, ofc...
The code to generate the file to be saved is the following:
const el = this.$refs.print
const options = {
type: 'dataURL',
useCors: true,
scale: 2,
logging: false,
}
try {
const canvas = await this.$html2canvas(el, options)
await Filesystem.writeFile({
path: `certificate-${this.photo.id}.jpeg`,
data: canvas,
directory: Directory.Documents,
})
} catch (error) {
// ...
}
It works, it gets the right portion of HTML and saves a Jpeg to my Documents, unfortunately, the images within are always total black...
Why??? How can I fix this?
You do not provide any encoding options to Filesystem.writeFile() and is therefore saved as base64 encoded per default. The HTML canvas-element is not base64 encoded.