winsontan520 / Android-WScratchView

[Deprecated] Provide a view which can be scratched
83 stars 35 forks source link

improvement of getScratchedRatio #20

Open razgrizbw opened 9 years ago

razgrizbw commented 9 years ago

The performance will have much improve if using Bitmap.getpixels in getScratchedRation()

replace the code with

final int width = mScratchedTestBitmap.getWidth();
final int height = mScratchedTestBitmap.getHeight();
int[] pixels = new int[width*height];
mScratchedTestBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
for (int i=0;i<pixels.length;i++) {
  if (0 == Color.alpha(pixels[i])) {
    count++;
  }
}
float completed = (float) count / ((width / speed) * (height / speed)) * 100;
return completed;