Skip to content

Latest commit

 

History

History
41 lines (37 loc) · 1.24 KB

HOW-TO.md

File metadata and controls

41 lines (37 loc) · 1.24 KB

Image source

Using the image source requires the image-source module.

var imageSource = require("image-source");

The pre-required imageSource module is used throughout the following code snippets. We also use fs module defined as follows:

var fs = require("file-system");

Loading and saving images

Load image using resource name

This is similar to loading Bitmap from R.drawable.logo on Android or calling [UIImage imageNamed@"logo"] on iOS

var img = imageSource.fromResource("logo");

Load image from URL

imageSource.fromUrl("http://www.google.com/images/errors/logo_sm_2.png").then(function (res) {
    console.log("Image successfully loaded");
}).fail(function (error) {
    console.log("Error loading image: " + error);
});

Save image source to PNG or JPG file

var img = imageSource.fromResource("logo");
var folder = fs.knownFolders.documents();
var path = fs.path.join(folder.path, "Test.png");
var saved = img.saveToFile(path, imageSource.ImageFormat.PNG);

Load image from a local file

var folder = fs.knownFolders.documents();
var path = fs.path.join(folder.path, "Test.png");
var img = imageSource.fromFile(path);