Scamble a Bitmap image

by John Woods » Wed, 12 May 2010 15:13:07 GMT

Sponsored Links
 I am new to android development. 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!

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,
        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);


Other Threads

1. How to keep the selected item of a ListView vertically centered?


1) A ListView with many items (i.e. scrolling will occur at some
2) At the beginning, the selection is at the top (item #0)
3) User is scrolling down (i.e. we're not in touch mode)
4) For the first items, the selection is moving down without the list
to scroll.
5) Once the selected item is reaching the middle of the list's
viewport: the list starts to scroll-down.
6) Then, toward the end of the list: scrolling stops and the selection
keeps moving down until the last item is reached.

It's a common feature in (keyboard-enabled) UI frameworks but I don't
believe it's possible to achieve with Android, as for now... Right?



2. Re-Register PhoneStateListener if application crashed

Any help ?


3. Should you develop unique UI's for each device?

4. Android Linux ( timed_outout & timed_gpio )

5. urgent: issue with media recorder

6. D-Pad and WebView

7. startForeground