i m trying to implement some image filters fro that i use this code
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageView=(ImageView) findViewById(R.id.imgView);
bgr = BitmapFactory.decodeResource(getResources(), R.drawable.test02);
int A, R, G, B;
int pixel;
// scan through all pixels
for(int x = 0; x < bgr.getWidth(); ++x)
{
for(int y = 0; y < bgr.getHeight(); ++y)
{
// get pixel color
pixel = bgr.getPixel(x, y);
A = Color.alpha(pixel);
R = Color.red(pixel);
G = Color.green(pixel);
B = Color.blue(pixel);
// increase/decrease each channel
R += value;
if(R > 255) { R = 255; }
else if(R < 0) { R = 0; }
G += value;
if(G > 255) { G = 255; }
else if(G < 0) { G = 0; }
B += value;
if(B > 255) { B = 255; }
else if(B < 0) { B = 0; }
// apply new pixel color to output bitmap
bgr.setPixel(x, y, Color.argb(A, R, G, B));
}
System.out.println("x");
}
imageView.setImageBitmap(bgr);
}
the problem is this is to slow is any other way to do it, OR make it faster..
You should read up about using a
ColorMatrix. This matrix can perform exactly the operation you are performing manually. In your case, since you are just adding a constant value to each component, your matrix would havea = g = m = s = 1, ande = j = o = value, and the rest of your matrix would be zeroes.Then you can use
setColorFilter()to apply aColorMatrixColorFilterto your ImageView.