You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var imageSource =require("tns-core-modules/image-source");
15
+
```
11
16
The pre-required `imageSource` module is used throughout the following code snippets.
12
17
We also use fs module defined as follows:
13
-
{%snippet imagesource-require-alt%}
18
+
```TypeScript
19
+
import*asfsfrom"tns-core-modules/file-system";
20
+
```
21
+
```JavaScript
22
+
var fs =require("tns-core-modules/file-system");
23
+
```
14
24
15
25
## Loading and saving images
26
+
16
27
### Load image using resource name
17
-
This is similar to loading Bitmap from `R.drawable.logo` on Android or calling `[UIImage imageNamed@"logo"]` on iOS
28
+
This is similar to loading Bitmap from `R.drawable.logo` on Android or calling `[UIImage imageNamed@"logo"]` on iOS.
29
+
The method `fromResource` creates an `ImageSource` instance and loads it from the specified resource name.
18
30
{%snippet imagesource-resname%}
19
31
20
-
### Load image from URL
21
-
{%snippet imagesource-load-url%}
22
-
23
-
### Save image source to PNG or JPG file
32
+
### Save image to PNG or JPG file
33
+
The method `saveToFile(path: string, format: "png" | "jpeg" | "jpg", quality?: number): boolean` saves `ImageSource` instance to the specified file, using the provided image format and quality.
34
+
The supported formats are `png`, `jpeg`, and `jpg`. The quality parameter is optional and defaults to maximum quality. Returns `true` if the file is saved successfully.
24
35
{%snippet imagesource-save-to%}
25
36
26
37
### Load image from a local file
38
+
Use `fromFile(path: string): Promise<boolean>` to load an `ImageSource` instance from the specified file asynchronously.
27
39
{%snippet imagesource-load-local%}
28
40
29
-
### Save image source from imageAsset to PNG file
30
-
{%snippet imagesource-from-imageasset-save-to%}
41
+
### Load image from URL
42
+
Use `http.getImage(url: string): Promise<ImageSource>` to fetch `ImageSource` from online source.
43
+
{%snippet http-get-image%}
44
+
45
+
### Save image from image asset to PNG file
46
+
Use `fromAsset(asset: ImageAsset): Promise<ImageSource>` to load `ImageSource` from the specified `ImageAsset` asynchronously.
47
+
{%snippet imagesource-from-imageasset-save-to%}
48
+
49
+
### Creating base64 string from PNG image file
50
+
The method `toBase64String(format: "png" | "jpeg" | "jpg", quality?: number): string` converts the image to base64 encoded string, using the provided image format and quality.
51
+
The supported formats are `png`, `jpeg`, and `jpg`. The quality parameter is optional and defaults to maximum quality.
52
+
{%snippet imagesource-to-base-string%}
53
+
54
+
### Creating PNG image file from base64 string
55
+
The method `fromBase64(source: string): Promise<boolean>` loads this instance from the specified base64 encoded string asynchronously.
0 commit comments