Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const test_ImageCache_NothingAtProvidedUrl = function () {
const cache = new imageCacheModule.Cache();
cache.maxRequests = 5;
let errorCaught = false;
let errorMessage: string;
let imgSource: imageSource.ImageSource;
const url = "https://github.com/NativeScript-NoImage.png";
// Try to read the image from the cache
const image = cache.get(url);
if (image) {
// If present -- use it.
imgSource = imageSource.fromNativeSource(image);
}
else {
// If not present -- request its download.
cache.push({
key: url,
url: url,
completed: (image: any, key: string) => {
if (url === key) {
imgSource = imageSource.fromNativeSource(image);
}
},
error: (key: string) => {
console.log("No image for key: ", key);
errorMessage = `No image for key: ${key}`;
errorCaught = true;
}
}
traceWrite(err, traceCategories.Debug);
}
});
}
} else if (value instanceof ImageSource) {
// Support binding the imageSource trough the src property
this.imageSource = value;
this.isLoading = false;
} else if (value instanceof ImageAsset) {
fromAsset(value).then((result) => {
this.imageSource = result;
this.isLoading = false;
});
} else {
this.imageSource = fromNativeSource(value);
this.isLoading = false;
}
}
}
return new Promise((resolve, reject) => {
try {
if (!img || !degree) {
reject('Missing required arguments');
}
const bmp = this._processor.tintImage(this._getBitmap(img), degree);
const isrc = fromNativeSource(bmp);
resolve(isrc);
} catch (err) {
reject(err);
}
});
}
return new Promise((resolve, reject) => {
try {
const data = this.nativeView.getSketch();
if (data) {
resolve(fromNativeSource(data));
} else {
reject('Pad is empty.');
}
} catch (err) {
reject(err);
}
});
}
return new Promise((resolve, reject) => {
try {
if (!img) {
reject('Image is required');
}
const bmp = this._processor.emboss(this._getBitmap(img));
const isrc = fromNativeSource(bmp);
resolve(isrc);
} catch (err) {
reject(err);
}
});
}
return new Promise((resolve, reject) => {
try {
if (!img || !watermark) {
reject('Missing required arguments');
}
const bmp = this._processor.waterMark(
this._getBitmap(img),
watermark,
location,
color,
alpha,
size,
underline
);
const isrc = fromNativeSource(bmp);
resolve(isrc);
} catch (err) {
reject(err);
}
});
}
onPixelCopyFinished: (copyResult: number) => {
if (copyResult === android.view.PixelCopy.SUCCESS) {
resolve(fromNativeSource(bitmap));
} else {
reject("Field to copy screen image")
}
handlerThread.quitSafely();
}
}), new android.os.Handler(handlerThread.getLooper()));
value = value.trim();
video["_url"] = value;
video.isLoadingProperty = true;
if (isFileOrResourcePath(value)) {
video.imageSource = imageSource.fromFileOrResource(value);
video.isLoadingProperty = false;
} else {
if (video["_url"] === value) {
video.imageSource = imageSource.fromUrl(value);
video.isLoadingProperty = false;
}
}
} else if (value instanceof imageSource.ImageSource) {
video.imageSource = value;
} else {
video.imageSource = imageSource.fromNativeSource(value);
}
}
return new Promise((resolve, reject) => {
try {
if (!img) {
reject('Image is required');
}
const bmp = this._processor.doGreyScale(this._getBitmap(img));
const isrc = fromNativeSource(bmp);
resolve(isrc);
} catch (err) {
reject(err);
}
});
}
return new Promise((resolve, reject) => {
try {
if (!img || !shadingColor) {
reject('Missing required arguments');
}
const bmp = this._processor.applyShadingFilter(
this._getBitmap(img),
shadingColor
);
const isrc = fromNativeSource(bmp);
resolve(isrc);
} catch (err) {
reject(err);
}
});
}