2

I am trying to change image color dynamically in android .but it takes to much time .

Below function is used for changing color.

  public void greenColor(ImageView imageView,String fileName){
                System.out.println("in green color method");

             //initialize the Bitmap Object  

              Bitmap  bmp = BitmapFactory.decodeFile(fileName);
               //  Bitmap bmp = ((BitmapDrawable)imageView.getDrawable()).getBitmap();  
                //Guarantees that the image is decoded in the ARGB8888 format  
                bmp = bmp.copy(Bitmap.Config.ARGB_8888, true);  



                //Initialize the intArray with the same size as the number of pixels on the image  
                int[] intArray  = new int[bmp.getWidth()*bmp.getHeight()];  

                //copy pixel data from the Bitmap into the 'intArray' array  
                bmp.getPixels(intArray, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());  



                //replace the red pixels with yellow ones  
                try{
                    for (int i=0; i < intArray.length; i++)  
                    {  
                        //System.out.println("pixel value :"+intArray[i]);
                        //intArray[i] =  0xFFFF0000;  

                        if(intArray[i] == Color.WHITE)  
                        {  

                           System.out.println("color white ");
                        } else{
                            System.out.println(intArray[i]);
                            intArray[i]=Color.GREEN;
                        }
                    }  
                }catch(Exception e){
                    System.out.println("pixel error "+e);
                }


                //Initialize the bitmap, with the replaced color  
                bmp = Bitmap.createBitmap(intArray, bmp.getWidth(), bmp.getHeight(), Bitmap.Config.ARGB_8888);  

                //Draw the bitmap with the replaced color  
                imageView.setImageBitmap(bmp);  
               //----end color

        }

I've tried so much and did google search, but i am unable to solve my problem ,

Is there any technique to reduce image color change time in android?

Please help me ...

Deepzz
  • 4,573
  • 1
  • 28
  • 52
Hemantvc
  • 2,111
  • 3
  • 30
  • 42
  • Have you read this article ? http://stackoverflow.com/questions/14251896/change-image-color-take-too-mach-time-in-android – Yahor10 Jan 10 '13 at 06:19
  • above link my own question . – Hemantvc Jan 10 '13 at 07:01
  • Sorry,wrong link.http://stackoverflow.com/questions/1309629/how-to-change-colors-of-a-drawable-in-android – Yahor10 Jan 10 '13 at 07:03
  • i was see your posted link,your link is not usefull for me, i am doing such type of task http://stackoverflow.com/questions/14208367/how-to-change-image-color-dynamically-in-android/14208530#comment19703813_14208530 – Hemantvc Jan 10 '13 at 12:57
  • Please, see if you can find your solution here https://github.com/jrvansuita/IconHandler – Vansuita Jr. Oct 12 '16 at 03:52

1 Answers1

2

in your case its taking time as you are converting the image into 2d array and checking at every index.

So if image if 2000*2000 size, just imagine how much you are processing. If you want to change the alfa or tint then you should use the Bitmap APIs instead of doing it manually.

akkilis
  • 1,904
  • 14
  • 21