mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(ios-image-source): standardize quality scale in image-source (#5517)
* feat(ios-image-source): standardize quality scale in image-source for both platforms Normalize quality in saveToFile and toBase64String to follow 0-100 scale - standardize implementation on both platforms closes #5474
This commit is contained in:
committed by
Alexander Vakrilov
parent
e1a1d643c8
commit
319c153360
@@ -54,6 +54,15 @@ export function testSaveToFile() {
|
||||
TKUnit.assert(fs.File.exists(path), "Image not saved to file");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
export function testFromFile() {
|
||||
// >> imagesource-load-local
|
||||
const folder = fs.knownFolders.documents();
|
||||
@@ -187,6 +196,16 @@ export function testBase64Encode_PNG() {
|
||||
"Base 64 encoded PNG");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
export function testBase64Encode_JPEG() {
|
||||
const img = imageSource.fromFile(smallImagePath);
|
||||
|
||||
@@ -199,6 +218,18 @@ export function testBase64Encode_JPEG() {
|
||||
"Base 64 encoded JPEG");
|
||||
}
|
||||
|
||||
export function testBase64Encode_JPEG_With_Quality() {
|
||||
const img = imageSource.fromFile(smallImagePath);
|
||||
|
||||
let base64String = img.toBase64String("jpeg", 80);
|
||||
base64String = base64String.substr(0, expectedJpegStart.length);
|
||||
|
||||
TKUnit.assertEqual(
|
||||
base64String,
|
||||
expectedJpegStart,
|
||||
"Base 64 encoded JPEG");
|
||||
}
|
||||
|
||||
export function testLoadFromBase64Encode_JPEG() {
|
||||
// >> imagesource-from-base-string
|
||||
let img: imageSource.ImageSource;
|
||||
|
||||
Reference in New Issue
Block a user