android - 在 Android 中更改图像颜色需要花费太多时间

标签 android

我正在尝试在 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中图像颜色变化的时间吗?

请帮助我...

最佳答案

在您的情况下,将图像转换为二维数组并检查每个索引需要时间。

因此,如果图像大小为 2000*2000,想象一下您要处理的量。 如果您想更改阿尔法或色调,那么您应该使用位图 API,而不是手动执行。

关于android - 在 Android 中更改图像颜色需要花费太多时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14251896/

相关文章:

java - 我应该在接收 Activity 作为参数的方法中放置什么?

android - RecyclerView 在 smoothScrollToPosition(0) 之后滚动结束

android - 如何使用 XML 布局以外的方式绘制自定义 View 装饰?

android - 如何在调用/接听电话时以编程方式打开扬声器?

java - Eclipse 版本控制 - 项目不再显示在工作区中的问题

java - Bug 在 SDK 1.5 下运行 Android 教程 HelloTabWidget : "setCurrentTag(getIntent())"

android - 为什么当我尝试从我的回收 View 中搜索某些内容时,我的数据会重复?

android - 设备开机或解锁时启动应用程序

java - 从文本文件读取无法正常工作

android - 场景转换闪烁