First, please don't hijack other posts and change their subject. As for your problem, it is probably very slow because of the size of the image you are using(ie a photo from the gallery (2-5mpx) ) Since you are on a mobile device with a limited screen, you could scale down the image to the display size say 320*480 using a bitmapfactory and a matrix and postscale or any other method.
Then your code would have a lot less pixels to scramble. Side note, but when you are trying to get speed any optimization helps : make a variable out of pixels.length - 1, that way the device doesn't have to compute that number for the 5 millions pixels your scrambling :) Yahel On 9 mai, 16:20, "John Woods" <[email protected]> wrote: > 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 > athttp://groups.google.com/group/android-developers?hl=en -- 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

