问题
I am creating an image filters app in android. I am retrieving pixels from a bitmap doing some rgb work on then and setting them on another bitmap. Here is my code and it isnt working properly. please help
bmOut = Bitmap.createBitmap(bm1.getWidth(),
bm1.getHeight(), bm1.getConfig());
final double GS_RED = 0.299;
final double GS_GREEN = 0.587;
final double GS_BLUE = 0.114;
int A, R, G, B;
int pixel;
int[] pixels = new int[bm1.getHeight()* bm1.getWidth()];
bm1.getPixels(pixels, 0, bm1.getWidth(), 0, 0,bm1.getWidth(), bm1.getHeight());
for (int pix = 0 ; pix< pixels.length;pix++) {
A = Color.alpha(pix);
R = Color.red(pix);
G = Color.green(pix);
B = Color.blue(pix);
R = G = B = (int) (GS_RED * R + GS_GREEN * G + GS_BLUE * B);
pixels[pix] = Color.argb(A, R, G, B);
}
bmOut.setPixels(pixels, 0, bm1.getWidth(), 0, 0,
bm1.getWidth(), bm1.getHeight());
来源:https://stackoverflow.com/questions/26573971/in-android-image-filter-application-getpixels-and-setpixels-not-working-properly