I have been asked to write an function to scramble a bitmap image. A user
can then enter a password and the image will unscramble.
I have managed to write the following code that works but takes way to long
to execute due to the setPixels call.
I was thinking of an alternate solution of just drawing the original
unscrambled image and then making some sort of transparent overlay bitmap
with some sort of distortion effect. When the user enters the correct
password the overlay fades away.
Please help!
@Override
protected void onDraw(Canvas canvas)
{
//Some of the variables are global but I left out that code. This
successfully runs.
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Bitmap scrambled = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
int[]pixels = new int[w*h];
bitmap.getPixels(pixels, 0, w, 0, 0, w, h);
int color = 0;
Random random = new Random();
Paint paint = new Paint();
for (int i = 0; i < pixels.length; i++)
{
pixels[i] = pixels[random.nextInt(pixels.length - 1)];
}
scrambled.setPixels(pixels, 0, w, 0, 0, w, h);
canvas.drawBitmap(scrambled, 0, 0, paint); }
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en