簡體   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