2

Androidで画像の色を動的に変更しようとしていますが、時間がかかります。

以下の関数は、色を変更するために使用されます。

  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

        }

私はたくさん試し、グーグル検索をしました、しかし私は私の問題を解決することができません、

Androidで画像の色の変更時間を短縮するテクニックはありますか?

私を助けてください ...

4

1 に答える 1

2

あなたの場合、画像を2D配列に変換し、すべてのインデックスでチェックするので時間がかかります。

したがって、2000 * 2000サイズの画像の場合、処理している量を想像してみてください。アルファまたは色合いを変更する場合は、手動で行うのではなく、ビットマップAPIを使用する必要があります。

于 2013-01-10T06:25:31.297 に答える