Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 8f89d96

Browse files
Show how to use a local file
1 parent f945040 commit 8f89d96

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

demo-ng/app/images/puppy.jpg

5.68 KB
Loading

demo-ng/app/tabs/mlkit/mlkit.component.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
<Label row="0" text="Pick the image processing source:" textWrap="true"></Label>
44

55
<FlexboxLayout row="1" flexDirection="row" justifyContent="space-around">
6-
<Button text="Cameraroll" textWrap="true" (tap)="fromCameraroll()" class="button"></Button>
6+
<Button text="Puppy" textWrap="true" (tap)="fromAppFolder()" class="button"></Button>
7+
<Button text="Cam roll" textWrap="true" (tap)="fromCameraroll()" class="button"></Button>
78
<!-- the image may require rotation on Android, and permission may be required - not feeling like exposing this for now -->
89
<iOS>
9-
<Button text="Cam picture" textWrap="true" (tap)="fromCameraPicture()" class="button"></Button>
10+
<Button text="Cam pic" textWrap="true" (tap)="fromCameraPicture()" class="button"></Button>
1011
</iOS>
1112
<Button text="Cam feed" textWrap="true" (tap)="fromCameraFeed()" class="button"></Button>
1213
</FlexboxLayout>

demo-ng/app/tabs/mlkit/mlkit.component.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component, NgZone } from "@angular/core";
22
import { RouterExtensions } from "nativescript-angular";
3-
import { ImageSource } from "tns-core-modules/image-source";
3+
import { fromFile, ImageSource } from "tns-core-modules/image-source";
4+
import * as fileSystemModule from "tns-core-modules/file-system";
45
import { action } from "tns-core-modules/ui/dialogs";
56
import { ImageAsset } from "tns-core-modules/image-asset";
67
import { isIOS } from "tns-core-modules/platform";
@@ -81,6 +82,18 @@ export class MLKitComponent {
8182
});
8283
}
8384

85+
fromAppFolder(): void {
86+
const folder = fileSystemModule.knownFolders.currentApp();
87+
const path = fileSystemModule.path.join(folder.path, "/images/puppy.jpg");
88+
const exists = fileSystemModule.File.exists(path);
89+
console.log(`Does it exist: ${exists}`);
90+
91+
const imageSource = fromFile(path);
92+
this.pickedImage = imageSource;
93+
// give the user some time to to see the picture
94+
setTimeout(() => this.selectMLKitFeature(imageSource), 500);
95+
}
96+
8497
fromCameraPicture(): void {
8598
if (!isIOS) {
8699
Camera.requestPermissions();
@@ -94,7 +107,7 @@ export class MLKitComponent {
94107
}).then(imageAsset => {
95108
new ImageSource().fromAsset(imageAsset).then(imageSource => {
96109
this.pickedImage = imageSource;
97-
// give the user some to to see the picture
110+
// give the user some time to to see the picture
98111
setTimeout(() => this.selectMLKitFeature(imageSource), 500);
99112
});
100113
});
@@ -133,7 +146,7 @@ export class MLKitComponent {
133146
this.zone.run(() => {
134147
this.pickedImage = imageSource;
135148
});
136-
// give the user some to to see the picture
149+
// give the user some time to to see the picture
137150
setTimeout(() => this.selectMLKitFeature(imageSource), 500);
138151
});
139152
})

0 commit comments

Comments
 (0)