1
나는 여기에 method.But를 작성하여 흑백 비트 맵에서 현재 비트 맵을 변환하려고하는데 모든 픽셀의 for 루프 때문에 변환하는 데 오랜 시간이 걸린다. 아니면 다른 방법이 있습니까? .. 도움을 주실 수 있습니다. 감사합니다.비트 맵을 수정하는 것이 매우 느립니다 ... 다른 방법이 있습니까?
내 코드 :
public Bitmap convert(Bitmap src) {
final double GS_RED = 0.299;
final double GS_GREEN = 0.587;
final double GS_BLUE = 0.114;
int A, R, G, B;
final int width = src.getWidth();
final int height = src.getHeight();
int pixels[] = new int[width * height];
int k = 0;
Bitmap bitmap = Bitmap.createBitmap(width, height, src.getConfig());
src.getPixels(pixels, 0, width, 0, 0, width, height);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int pixel = pixels[x + y * width];
A = Color.alpha(pixel);
R = Color.red(pixel);
G = Color.green(pixel);
B = Color.blue(pixel);
R = G = B = (int) (GS_RED * R + GS_GREEN * G + GS_BLUE * B);
pixels[x + y * width] = Color.argb(
A, R, G, B);
}
}
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
가능한 복제 [블랙으로 컬러 이미지를 만드는 방법 and white in Android] (https://stackoverflow.com/questions/10185443/how-to-make-the-color-image-to-black-and-white-in-android) – R2R
ColorMatrices를 사용하십시오. 픽셀 단위로 이미지를 스캔하는 대신 전체 컬러 맵에서 한 번에 작업합니다. 그리고 다양한 효과를 낼 수 있습니다. –