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. override back button

Can someone help me understand how to stop the back button from
exiting out of my program?  I want it to just return to my main menu
or exit if pressed on the main menu but when I override the method it
still exits.  Here is what I currently have:

                public boolean onKeyDown(int keyCode, KeyEvent event)  {
                    if (keyCode == KeyEvent.KEYCODE_BACK && 
== 0) {
                        if (animation.state != 1){
                                animation.state = 1;
                                return true;
                        else return false;

                    return super.onKeyDown(keyCode, event);

I have messed with it a little but my program is always still closes.


2. Quick Search Box - Getting results in "All"

I can get search results in my app's search area (selecting the app
icon in the 2.3 quick search box to restrict the search to my app).

However, i dont see any of my results when All is selected.  Does
android just deprioritize them?  What determines what search results
show up in the All category?  Is there something I need to do?



3. username and password for sample sync adapter

4. [WTA] Lagfix Samsung Galaxy S

5. Force close after adding resources and textview

6. Galaxy Tab bisa jalanin Flash ?

7. Motorola DEFY LCD