本文整理匯總了TypeScript中tns-core-modules/image-source.fromFile函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript fromFile函數的具體用法?TypeScript fromFile怎麽用?TypeScript fromFile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了fromFile函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: test_DummyTestForSnippetOnly
export function test_DummyTestForSnippetOnly() {
// >> image-cache-request-images
var cache = new imageCacheModule.Cache();
cache.placeholder = imageSource.fromFile(fs.path.join(__dirname, "res/no-image.png"));
cache.maxRequests = 5;
// Enable download while not scrolling
cache.enableDownload();
var imgSouce: imageSource.ImageSource;
var url = "https://github.com/NativeScript.png";
// Try to read the image from the cache
var image = cache.get(url);
if (image) {
// If present -- use it.
imgSouce = imageSource.fromNativeSource(image);
}
else {
// If not present -- request its download.
cache.push({
key: url,
url: url,
completed: (image: any, key: string) => {
if (url === key) {
imgSouce = imageSource.fromNativeSource(image);
}
}
});
}
// Disable download while scrolling
cache.disableDownload();
// << image-cache-request-images
}
示例2: testNativeFields
export function testNativeFields() {
const img = imageSource.fromFile(imagePath);
if (app.android) {
TKUnit.assert(img.android != null, "Image.android not updated.");
} else if (app.ios) {
TKUnit.assert(img.ios != null, "Image.ios not updated.");
}
}
示例3: testSaveToFile_WithQuality
export function testSaveToFile_WithQuality() {
const img = imageSource.fromFile(imagePath);
const folder = fs.knownFolders.documents();
const path = fs.path.join(folder.path, "test.png");
const saved = img.saveToFile(path, "png", 70);
TKUnit.assert(saved, "Image not saved to file");
TKUnit.assert(fs.File.exists(path), "Image not saved to file");
}
示例4: testBase64Encode_PNG_WithQuality
export function testBase64Encode_PNG_WithQuality() {
const img = imageSource.fromFile(smallImagePath);
let base64String = img.toBase64String("png", 80);
base64String = base64String.substr(0, expectedPngStart.length);
TKUnit.assertEqual(
base64String,
expectedPngStart,
"Base 64 encoded PNG");
}
示例5: testSaveToFile
export function testSaveToFile() {
// >> imagesource-save-to
const img = imageSource.fromFile(imagePath);
const folder = fs.knownFolders.documents();
const path = fs.path.join(folder.path, "test.png");
const saved = img.saveToFile(path, "png");
// << imagesource-save-to
TKUnit.assert(saved, "Image not saved to file");
TKUnit.assert(fs.File.exists(path), "Image not saved to file");
}
示例6: testBase64Encode_PNG
export function testBase64Encode_PNG() {
const img = imageSource.fromFile(smallImagePath);
let result = img.toBase64String("png");
result = result.substr(0, expectedPngStart.length);
TKUnit.assertEqual(
result,
expectedPngStart,
"Base 64 encoded PNG");
}
示例7: testBase64Encode_JPEG
export function testBase64Encode_JPEG() {
const img = imageSource.fromFile(smallImagePath);
let base64String = img.toBase64String("jpeg");
base64String = base64String.substr(0, expectedJpegStart.length);
TKUnit.assertEqual(
base64String,
expectedJpegStart,
"Base 64 encoded JPEG");
}
示例8: testBase64Encode_JPEG
export function testBase64Encode_JPEG() {
var img = imageSource.fromFile(smallImagePath);
var result = img.toBase64String("jpeg");
result = result.substr(0, expectedJpegStart.length);
TKUnit.assertEqual(
result,
expectedJpegStart,
"Base 64 encoded JPEG");
}
示例9: testBase64Encode_PNG
export function testBase64Encode_PNG() {
// >> imagesource-to-base-string
const img = imageSource.fromFile(smallImagePath);
let base64String = img.toBase64String("png");
// << imagesource-to-base-string
base64String = base64String.substr(0, expectedPngStart.length);
TKUnit.assertEqual(
base64String,
expectedPngStart,
"Base 64 encoded PNG");
}
示例10: testFromFile
export function testFromFile() {
// >> imagesource-load-local
const folder = fs.knownFolders.documents();
const path = fs.path.join(folder.path, "test.png");
const img = imageSource.fromFile(path);
// << imagesource-load-local
TKUnit.assert(img.height > 0, "image.fromResource failed");
// remove the image from the file system
const file = folder.getFile("test.png");
file.remove();
TKUnit.assert(!fs.File.exists(path), "test.png not removed");
}