다음은 RGB 색상을 얻고 비트 맵 (다른 비트 맵)의 색상이 녹색 인 경우 temp (비트 맵)의 색상을 변경하는 방법입니다. 그러나 성능은 상당히 좋지 않으며 시간은 약 20 초 이상 사용됩니다. 그것을 개선 할 수있는 방법이 있습니까? 고맙습니다.안드로이드에서 RGB를 더 빨리 가져 오기
//get the green color of each pixel
color = new int[bitmap.getWidth()][bitmap.getHeight()];
for (int x = 0; x < bitmap.getWidth(); x++) {
for (int y = 0; y < bitmap.getHeight(); y++) {
color[x][y] = temp.getPixel(x, y);
if (bitmap.getPixel(x, y) == Color.GREEN) {
color[x][y] = temp.getPixel(x, y);
float[] hsv = new float[3];
Color.RGBToHSV(Color.red(color[x][y]), Color.green(color[x][y]), Color.blue(color[x][y]), hsv);
hsv[0] = 360;
color[x][y] = Color.HSVToColor(hsv);
}
temp.setPixel(x, y, color[x][y]);
}
}
imageView.setImageBitmap(temp);
업데이트 :
intArray = new int[bitmap.getWidth()*bitmap.getHeight()];
bitmap.getPixels(intArray,0,bitmap.getWidth(),0,0,bitmap.getWidth(),bitmap.getHeight());
int[] tempArray = new int[bitmap.getWidth()*bitmap.getHeight()];
temp.getPixels(tempArray,0,temp.getWidth(),0,0,bitmap.getWidth(),bitmap.getHeight());
//get the color of each pixel
color = new int[bitmap.getWidth()][bitmap.getHeight()];
for (int x = 0; x < bitmap.getWidth(); x++) {
for (int y = 0; y < bitmap.getHeight(); y++) {
if (intArray[x + y * bitmap.getWidth()] == Color.BLUE) {
float[] hsv = new float[3];
Color.RGBToHSV(Color.red(tempArray[x + y * bitmap.getWidth()]), Color.green(tempArray[x + y * bitmap.getWidth()]), Color.blue(tempArray[x + y * bitmap.getWidth()]), hsv);
hsv[0] = 360;
tempArray[x + y * bitmap.getWidth()] = Color.HSVToColor(hsv);
}
}
}
temp.setPixels(tempArray,0,temp.getWidth(),0,0,temp.getWidth(),temp.getHeight());
imageView.setImageBitmap(temp);
답장을 보내 주셔서 감사합니다. 2 차원 배열처럼 픽셀 데이터를 직접 작업하는 것이 좋습니다. <- 나는 이것에 상당히 흥미가있다. 좀 더 설명해 주시겠습니까? – ng2b30
@ ng2b30'getPixel()'과'setPixel()'을 사용하는 대신 픽셀 배열에 직접 접근 할 수 있는데, 이렇게하면 훨씬 더 빠릅니다 :'byte [] pixels = ((DataBufferByte) bufferedImage.getRaster(). getDataBuffer()) .getData();'- see http://stackoverflow.com/questions/6524196/java-get-pixel-array-from-image –
질문이 있습니다. 갤러리에서 PNG 이미지를 불러 와서 bufferedImage로 바꾸려면 어떻게해야하나요? 감사. – ng2b30