"grayscaled bitmap"(1 바이트 -> 1 픽셀)에 해당하는 바이트 배열이 있으며이 이미지의 PNG 파일을 만들어야합니다.android의 그레이 스케일 비트 맵
아래의 방법이 작동하지만, 사용중인 비트 맵이 1 바이트 대신 픽셀 당 4 바이트를 차지하므로 비트 맵이 거대합니다.
ARGB_8888 이외의 다른 Bitmap.Config와 함께 작동시키지 못했습니다. 어쩌면 ALPHA_8이 내가 필요로하는 것이지만, 제대로 작동하지 못했습니다.
나는 또한 다른 게시물 (Convert a Bitmap to GrayScale in Android)에 포함되어있는 toGrayScale 메서드를 시도했지만 크기와 동일한 문제가 있습니다.
public static boolean createPNGFromGrayScaledBytes(ByteBuffer grayBytes, int width,
int height,File pngFile) throws IOException{
if (grayBytes.remaining()!=width*height){
Logger.error(Tag, "Unexpected error: size mismatch [remaining:"+grayBytes.remaining()+"][width:"+width+"][height:"+height+"]", null);
return false;
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
// for each byte, I set it in three color channels.
int gray,color;
int x=0,y=0;
while(grayBytes.remaining()>0){
gray = grayBytes.get();
// integer may be negative as byte is signed. make them positive.
if (gray<0){gray+=256;}
// for each byte, I set it in three color channels.
color= Color.argb(-1, gray, gray, gray);
bitmap.setPixel(x, y, color);
x++;
if (x==width){
x=0;
y++;
}
}
FileOutputStream fos=null;
fos = new FileOutputStream(pngFile);
boolean result= bitmap.compress(Bitmap.CompressFormat.PNG,100,fos);
fos.close();
return result;
}
편집 : 생성 된 파일에 링크 (말도 안되는 것처럼 보이지만 방금 랜덤 데이터로 생성 됨). http://www.tempfiles.net/download/201208/256402/huge_png.html
도움을 주시면 대단히 감사하겠습니다.
"거대한"을 정의하십시오. 저의 이미지 편집 프로그램은 회색조 PNG보다 40 % 정도 큰 투명도의 RGB PNG를 만듭니다. 300 % 더 많은 데이터를 고려하면 나쁘지 않습니다. –
원본 회색 음영 png는 1732K입니다. 위의 절차로 만든 png는 5445K – richardtz
와우입니다. PNG 압축기의 버그와 비슷합니다. 5445K 결과를 가져 와서 많은 PNG 압축기 중 하나를 통해 실행하면 결과가 얼마나 큽니까? 그 파일을 어딘가에 게시 할 수 있습니까? –