ImageSource.saveToFile does not work with format 'jpg'
See original GitHub issueTell us about the problem
Trying to write an ImageSource to a file does not work on iOS when specifying βjpgβ as format (βjpegβ works fine).
Which platform(s) does your issue occur on?
iOS simulator (waiting for apple to approve my dev account to be able to deploy/test to real iOS device)
Please provide the following version numbers that your issue occurs with:
$ tns info
All NativeScript components versions information
ββββββββββββββββββββ¬ββββββββββββββββββ¬βββββββββββββββββ¬ββββββββββββββ
β Component β Current version β Latest version β Information β
β nativescript β 3.2.1 β 3.2.1 β Up to date β
β tns-core-modules β 3.2.0 β 3.2.0 β Up to date β
β tns-android β 3.2.0 β 3.2.0 β Up to date β
β tns-ios β 3.2.0 β 3.2.0 β Up to date β
ββββββββββββββββββββ΄ββββββββββββββββββ΄βββββββββββββββββ΄ββββββββββββββ
Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.
const targetFilename = 'test.jpg';
const tempPath = fs.knownFolders.temp().path;
const localFullPath = fs.path.join(tempPath, targetFilename);
let saved = imageSrc.saveToFile(localFullPath, 'jpeg'); // format 'jpg' does NOT work on iOS!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:14 (7 by maintainers)
Top Results From Across the Web
How to know if ImageSource is a jpg or png file - Stack Overflow
Looking at the docs for the "saveToFile" method, I don't think it matters what it was. You could try picking a jpeg and...
Read more >ImageSource module - NativeScript Docs
The ImageSource module provides methods for creating an image from different sources(local images, images from resource folder and base64 string ).
Read more >Image.Save Method (System.Drawing) - Microsoft Learn
Saves this image to the specified stream in the specified format. ... Saving the image to the same file it was constructed from...
Read more >Resizing Images in Nativescript - Tips, Tech and Tidbits
We won't know the actual image dimensions until the ImageAsset is used to create an ImageSource . We'll first add a check on...
Read more >SaveToFile Method | TestComplete Documentation
If the parameter specifies a file residing in a non-existent location, the method will fail to save the file. To avoid possible problems,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The code seems to be identical but itβs not π
In the first solution I use source.saveToFile() and source is the reference to ImageSource used to load image by .fromAsset() method (and works on android returning TRUE). In the second solution I use result.saveToFile() and result is the reference to a new ImageSource returned by the Promise.
What works on ANDROID (commented):
What works on iOs (not tested on Android):
@tsonevn I am actually using the Angular 2 version, but even your example doesnβt work for me. After tapping I donβt see any image, and also changing these lines below in main-page.ts, will print
CONSOLE LOG file:///app/main-page.js:45:16: saved: false
I am testing on iOS simulator Version 10.0 (SimulatorApp-745.10).