我正在尝试访问本地图像的RGBA像素。我正在使用Appcelerator Alloy开发并使用Hyperloop,这是我的代码。
var myUri = Uri.parse(result.media.nativePath.toString());
var imgBitmapFactory = BitmapFactory.decodeFile(myUri.getPath());
var width = imgBitmapFactory.getWidth();
var height = imgBitmapFactory.getHeight();
var pixelsArray = [],
pixel = 0;
for (var x = 0; x < width; ++x) {
for (var y = 0; y < height; ++y) {
//get pixel Color
pixel = imgBitmapFactory.getPixel(x, y);
//push rgba color into array
pixelsArray.push(Color.red(pixel), Color.green(pixel), Color.blue(pixel), Color.alpha(pixel))
}
}
一切工作都很好,直到width = 10和height =10。使用更高的width和height循环,它确实很慢,并且黑屏直到完成。 所以我的问题是:您知道此代码的更好实现或优化吗?我已经尝试使用webview,HTML5 canvas和Inject JS,但是可以使用Android bug(SafeBrowser ....)让我执行getImageData()。我也尝试过使用
imgBitmapFactory.getPixels(new Array(width*height), 0, width, 0, 0, width, height)
但我收到此错误:
[INFO] : zygote64: Background concurrent copying GC freed 3936(205KB) AllocSpace objects, 1(20KB) LOS objects, 32% free, 49MB/73MB, paused 205us total 176.914ms
[ERROR] : HyperloopProxy: (main) [12653,12653] Unable to resolve method call. Class: android.graphics.Bitmap, method name: getPixels, args: [[Ljava.lang.Object;@17c7597, 0, 4000, 0, 0, 4000, 3000]
[INFO] : null
[INFO] : Choreographer: Skipped 476 frames! The application may be doing too much work on its main thread.
感谢您的帮助!