MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / pickImage

Method pickImage

apps/toolbox/src/pages/image-handling.ts:18–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16 symbolRotateEffect = ImageSymbolEffects.Rotate;
17
18 pickImage() {
19 const context = create({
20 mode: 'single',
21 mediaType: ImagePickerMediaType.Image,
22 });
23
24 context
25 .authorize()
26 .then(() => {
27 return context.present();
28 })
29 .then((selections) => {
30 const selection = selections.length > 0 ? selections[0] : null;
31 if (selection) {
32 this.addingPhoto = true;
33 const imageAsset = selection.asset;
34
35 ImageSource.fromAsset(imageAsset).then(
36 (savedImage) => {
37 const folder = knownFolders.documents();
38 const filePath = path.join(folder.path, `assets-${Date.now()}.jpg`);
39 console.log('filePath:', filePath);
40
41 const saved = savedImage.saveToFile(filePath, 'jpg');
42 if (saved) {
43 console.log(`file saved:`, filePath);
44 } else {
45 console.log('file not saved!');
46 }
47 this.addingPhoto = false;
48 },
49 (err) => {
50 this.addingPhoto = false;
51 },
52 );
53 }
54 })
55 .catch((e) => {
56 console.log(e);
57 });
58 }
59}

Callers

nothing calls this directly

Calls 6

presentMethod · 0.80
joinMethod · 0.80
createFunction · 0.50
fromAssetMethod · 0.45
logMethod · 0.45
saveToFileMethod · 0.45

Tested by

no test coverage detected