2012-05-16 34 views
0

我用下面的代码将普通图像转换为灰度和棕褐色的图像。如何减少当我将普通图像转换为棕褐色图像时的时间消耗?

棕褐色转换

public static Bitmap createSepiaToningEffect(Bitmap src, int depth, 
      double red, double green, double blue) { 
     // image size 
     int width = src.getWidth(); 
     int height = src.getHeight(); 
     // create output bitmap 
     Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig()); 
     // constant grayscale 
     final double GS_RED = 0.3; 
     final double GS_GREEN = 0.59; 
     final double GS_BLUE = 0.11; 
     // color information 
     int A, R, G, B; 
     int pixel; 

     // scan through all pixels 
     for (int x = 0; x < width; ++x) { 
      for (int y = 0; y < height; ++y) { 
       // get pixel color 
       pixel = src.getPixel(x, y); 
       // get color on each channel 
       A = Color.alpha(pixel); 
       R = Color.red(pixel); 
       G = Color.green(pixel); 
       B = Color.blue(pixel); 
       // apply grayscale sample 
       B = G = R = (int) (GS_RED * R + GS_GREEN * G + GS_BLUE * B); 

       // apply intensity level for sepid-toning on each channel 
       R += (depth * red); 
       if (R > 255) { 
        R = 255; 
       } 

       G += (depth * green); 
       if (G > 255) { 
        G = 255; 
       } 

       B += (depth * blue); 
       if (B > 255) { 
        B = 255; 
       } 

       // set new pixel color to output image 
       bmOut.setPixel(x, y, Color.argb(A, R, G, B)); 
      } 
     } 

     // return final image 
     return bmOut; 
    } 

上面的代码工作正常,但问题是它需要更多的时间(超过60秒)。我怎样才能减少时间消耗。当我把图像转换成灰度时,它需要不到2秒。任何人都可以帮助我解决这个问题。

回答

1

你可以使用NDK它是指这个混帐混帐库://github.com/ruckus/android-image-filter-ndk.git

+0

有任何库可用于这个 – Aerrow

+0

你也可以检查http://xjaphx.wordpress.com/learning/tutorials/它有纯java解决方案,但我认为使用ndk会处理更快 –

+0

已经我reffed,我也只使用该代码,但它需要更多时间 – Aerrow

相关问题