我发现开源模糊背景图片代码并使用我的项目,但有时会出现此错误。不是所有的时间。
java.lang.ArrayIndexOutOfBoundsException: length=1290496; index=1297040
at com.cleanwiz.applock.utils.FastBlur.doBlur(FastBlur.java:130)
at com.cleanwiz.applock.ui.activity.GestureUnlockActivity.blur(GestureUnlockActivity.java:524)
at com.cleanwiz.applock.ui.activity.GestureUnlockActivity.access$200(GestureUnlockActivity.java:76)
at com.cleanwiz.applock.ui.activity.GestureUnlockActivity$1.onPreDraw(GestureUnlockActivity.java:159)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:833)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1860)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
这里我的FastBlur.doBlur(FastBlur.java:130)
for (x = 0; x < w; x++) {
r[yi] = dv[rsum];
g[yi] = dv[gsum];
b[yi] = dv[bsum];
rsum -= routsum;
gsum -= goutsum;
bsum -= boutsum;
stackstart = stackpointer - radius + div;
sir = stack[stackstart % div];
routsum -= sir[0];
goutsum -= sir[1];
boutsum -= sir[2];
这里我的GestureUnlockActivity.blur(GestureUnlockActivity.java:524)
private void blur(Bitmap bkg, View view) {
long startMs = System.currentTimeMillis();
float radius = 70;
float scaleFactor = 8;
Bitmap overlay = Bitmap.createBitmap(
(int) (view.getMeasuredWidth() / scaleFactor),
(int) (view.getMeasuredHeight() / scaleFactor),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(overlay);
canvas.translate(-view.getLeft() / scaleFactor, -view.getTop()
/ scaleFactor);
canvas.scale(1 / scaleFactor, 1 / scaleFactor);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(bkg, 0, 0, paint);
overlay = FastBlur.doBlur(overlay, (int) radius, true);
view.setBackgroundDrawable(new BitmapDrawable(getResources(), overlay));
}
这里我的GestureUnlockActivity $ 1.onPreDraw(GestureUnlockActivity.java:159)
blur(big(bmp), backLinearLayout);
这里是我的数组
int[] pixex = new int[w * h];
List<Integer> trIndexs = new ArrayList<Integer>();
for (int i = 0; i < bitmap.getHeight(); i++) {
for (int j = 0; j < bitmap.getWidth(); j++) {
int color = bitmap.getPixel(j, i);
int alpha = Color.alpha(color);
if (alpha < 200) {
trIndexs.add(i * h + j);
} else if (trIndexs.size() > 0) {
for (Integer tr : trIndexs) {
pixex[tr] = color;
}
trIndexs.clear();
pixex[i * h + j] = color;
} else {
pixex[i * h + j] = color;
}