钛像厂质量

时间:2014-04-25 06:47:25

标签: titanium titanium-mobile appcelerator titanium-modules

我有这个代码在iOS上完美运行但在android平台上崩溃。

var quality = Ti.Platform.osname=="android"?80:ImageFactory.QUALITY_LOW;
Ti.API.info(quality);
var resizedImage = ImageFactory.imageAsResized(imageView, {height : h,width:w, quality: quality});

第二行代码显示80,但我收到一条错误

[INFO] :   80
[WARN] :   W/System.err: java.lang.IllegalArgumentException: quality must be 0..100
[WARN] :   W/System.err:    at android.graphics.Bitmap.compress(Bitmap.java:873)
[WARN] :   W/System.err:    at ti.imagefactory.ImageFactoryModule.imageTransform(ImageFactoryModule.java:137)
[WARN] :   W/System.err:    at ti.imagefactory.ImageFactoryModule.imageAsResized(ImageFactoryModule.java:181)
[WARN] :   W/System.err:    at org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method)
[WARN] :   W/System.err:    at org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:57)
[WARN] :   W/System.err:    at org.appcelerator.kroll.runtime.v8.V8Function.call(V8Function.java:43)
[WARN] :   W/System.err:    at org.appcelerator.kroll.runtime.v8.V8Function$1.run(V8Function.java:70)
[WARN] :   W/System.err:    at android.os.Handler.handleCallback(Handler.java:725)
[WARN] :   W/System.err:    at android.os.Handler.dispatchMessage(Handler.java:92)
[WARN] :   W/System.err:    at android.os.Looper.loop(Looper.java:137)
[WARN] :   W/System.err:    at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
[ERROR] :  TiExceptionHandler: (main) [454,43722] ----- Titanium Javascript Runtime Error -----
[ERROR] :  TiExceptionHandler: (main) [0,43722] - In views/share.js:58,34
[ERROR] :  TiExceptionHandler: (main) [0,43722] - Message: Uncaught Error: quality must be 0..100
[ERROR] :  TiExceptionHandler: (main) [0,43722] - Source:
[ERROR] :  V8Exception: Exception occurred at views/share.js:58: Uncaught Error: quality must be 0..100

出了什么问题?

2 个答案:

答案 0 :(得分:1)

试试这个

if (Ti.Platform.osname=="android"){
    // For android
    resizedImage = ImageFactory.imageAsResized(imageView, {height : h,width:w});
}else{
    // For iOS
    resizedImage = ImageFactory.imageAsResized(imageView, {height : h,width:w, quality: quality});
}

有关详情,请参阅android的app.js和iOS

答案 1 :(得分:0)

对于图像大小调整,您可以使用。

[TiBlob] imageAsResized([int] width, [int] height)

示例: -

var blob = myimage.toBlob();
var smallBlob = blob.imageAsResized(80, 80);

refer