MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / save

Method save

apps/toolbox/src/pages/image-async.ts:14–34  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12 savedData: string = '';
13 resizedImage: ImageSource;
14 async save() {
15 try {
16 const imageSource = await ImageSource.fromUrl(this.src);
17 const tempFile = path.join(knownFolders.temp().path, `${Date.now()}.jpg`);
18 const base64 = imageSource.toBase64StringAsync('jpg');
19 const image = imageSource.saveToFileAsync(tempFile, 'jpg');
20 const resizedImage = imageSource.resizeAsync(50);
21 const results = await Promise.all([image, base64, resizedImage]);
22 const saved = results[0];
23 const base64Result = results[1];
24 if (saved) {
25 this.notifyPropertyChange('savedData', tempFile);
26 console.log('ImageAsset saved', saved, tempFile);
27 }
28 console.log('base64', base64Result);
29 console.log(results[2].width, results[2].height);
30 this.notifyPropertyChange('resizedImage', results[2]);
31 } catch (e) {
32 console.log('Failed to save ImageAsset');
33 }
34 }
35}

Callers 2

drawMethod · 0.80
drawMethod · 0.80

Calls 7

joinMethod · 0.80
notifyPropertyChangeMethod · 0.80
fromUrlMethod · 0.45
toBase64StringAsyncMethod · 0.45
saveToFileAsyncMethod · 0.45
resizeAsyncMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected