繁体   English   中英

如何压缩Titanium Appcelerator中的IMAGE大小

[英]How to Compress the IMAGE size in Titanium Appcelerator

我正在使用钛2.0.1,我需要压缩相机拍摄的图像的大小,然后上传它。 现在图像大小为800kb +,需要花费大量时间上传。 我需要压缩大小。 任何人都可以告诉我如何做到这一点。

Titanium似乎默认以“高”质量导出图像,无法将压缩设置调整到较低质量(没有第三方模块)。 如果将Titanium生成的JPG与通过Photoshop的Save for Web JPEG“High”功能导出的JPG进行比较,您会发现Ti图像的文件大小要大得多。

您可以尝试以下模块之一:

iOS和Android:marketplace.appcelerator.com/apps/1184?540167410

仅适用于iOS: https//github.com/gudmundurh/titanium-imaging

Android Only: https//github.com/novelys/titanium-jpegencoder

图像不会压缩太多,因为许多图像格式已经压缩图像,如jpeg。 我在3118 KB jpg图像上尝试了zip和7zip,zip压缩到3114 KB,而7zip将其大小增加到3121 KB。

如果您仍想压缩图像大小,可以尝试使用此javascript代码进行压缩: https//github.com/TermiT/ZipFile 它可能会使您的上传时间更慢,因为您必须等待应用程序压缩图像并等待应用程序上传它。

如果您不介意上传尺寸较小的图像,这也会使文件尺寸变小,您可以使用Titanium的imageAsResized方法。 在Titanium 2.0之前,该方法在Android中无效。 我还没有在Titanium 2.0中测试它,看看它现在是否适用于Android。

你可能想要看的其他东西是网络连接速度(无线,3G,4G)。 也许你的测试是在缓慢的连接上。

赞成的答案似乎已经过时了。

https://github.com/appcelerator-modules/ti.imagefactory是一个在iOS和Android上运行的最新模块,允许使用Appcelerator / Axway / Titanium进行图像处理。

https://github.com/appcelerator-modules/ti.imagefactory/blob/stable/ios/example/app.js中的一些示例

btnSave.addEventListener('click', function (e) {
newBlob = ImageFactory.compress(blob, 0.25);
var filename = Titanium.Filesystem.applicationDataDirectory + "/newflower.jpg";
f = Titanium.Filesystem.getFile(filename);
f.write(newBlob);
var alert = Ti.UI.createAlertDialog({
    title:'Image Factory',
    message:'Compressed image saved to newflower.jpg with compression quality of 25%'
});
alert.show();

});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM