question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImageSource.saveToFile does not work with format 'jpg'

See original GitHub issue

Tell 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
gepisolocommented, Jan 24, 2018

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):

      const source = new imageSource.ImageSource(); // New instance of IMAGESOURCE
      source.fromAsset(picture).then((result) => { 
        const saved = source.saveToFile(path, "png"); // <= use **source**.saveToFile
        console.log(saved); //True on ANDROID but false on IOS
      });

What works on iOs (not tested on Android):

     const source = new imageSource.ImageSource();
      source.fromAsset(picture).then((result) => {
        
        const saved = result.saveToFile(path, "png"); // <= use the result which is returned by the Promise 
        console.log(saved); //True on IOS - not tested on android
      });
1reaction
abhayastudioscommented, Sep 25, 2017

@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

var saved = imagesourcetest.saveToFile(localFullPath, "jpg");
console.log(`saved: ${saved}`);

I am testing on iOS simulator Version 10.0 (SimulatorApp-745.10).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found