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!

@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);
}

--



Other Threads

1. onClickListener of a view

Hi
    I have the following code:

                int x = (int)Math.round(Math.random()*200);
                int y = (int)Math.round(Math.random()*300);
                
                View h = new CustomDrawableView(c,x,y);
                h.setLayoutParams(new ViewGroup.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT));
        
                h.setOnClickListener(new OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                        // TODO Auto-generated method stub
                                        Log.d("VIEW",v.toString());
                                        v.setVisibility(View.INVISIBLE);
                                }
                        
                });

inside an Handler, that create every 2 seconds a new ovalShape and add
it to the Layout.
Everything works fine, except for the clickListener. In fact, when i
press one of my shapes on the screen, it will be made invisible only
the last one, and not what I clicked.

Am I missing something?
--
Luca Bedogni
{*filter*} Web Developer
 http://www.***.com/ 

-- 

2. Staging Generated C/C++ Headers

I am looking for a little insight from someone familiar with the
Android Make System.    I am writing a tool to auto-generate C
Marshallers for AIDL files.   I would like to figure out how to stage
these header from a library project such that other applications can
include these in their path.   I had a few questions

Are there good examples of projects that stage there C C++ headers to
that other projects can include them?
Are there any examples of projects that generate C C++ code that stage
it for other project use?

I am currently building out of Eclair.  I've found a few things for
LOCAL_COPY_HEADER, but it seems to only stage non-generated headers
and I am currently using LOCAL_GENERATED_SOURCES to make sure my
autogenerated files compile properly.

Keith Preston

-- 

3. Wireshark not showing HTTP packets for emulator

4. Need help: How to create Surfaces in Native layer(equivalent of view->getholder->getsurface)

5. How to create graphical/advanced menus??

6. unknown reloc type error

7. No Network Connectivity in Service/AlarmManager Process.