Flickr에서 다운로드 한 사진을 표시하는 Android 앱에서 작업 중입니다. 다음과 같이 나는 다시 관련 플리커 URL에서 읽은 바이트 배열에서 비트 맵 오브젝트를 취득 :Android : BitmapFactory.decodeByteArray는 픽셀 화 된 비트 맵을 제공합니다.
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inDither = true;
opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, opt);
내가 다음보기 개체의 된 onDraw 방법에 캔버스에 비트 맵을 그릴 :
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(bitmap, 0, 0, paint);
문제는 결과로 나타나는 그림이 픽셀 화되어 있고 그 이유를 파악할 수 없다는 것입니다. opt 및 paint 객체의 여러 변형을 행운으로 시도했습니다.
Bad image, see pixelation in top left corner http://homepages.inf.ed.ac.uk/s0677975/bad.jpg
Good picture, this is the expected result http://homepages.inf.ed.ac.uk/s0677975/good.jpg
봐 예 : 내 응용 프로그램에 표시되는 화면과 원래의 URL에서 그림 사이의 차이는 대략 다음에 의해 증명된다 그 차이를보기 위해 왼쪽 상단에있는 구름에.
프로젝트 리소스에서로드되어 비슷한 방식으로 그려진 JPEG 그림은 픽셀이 표시되지 않는 점을 유의하십시오.
아무도 내게 왜 이런 일이 일어날 지에 대한 힌트를 줄 수 있습니까?
조금 더 자세히 설명하기 위해 바이트 배열은 다음과 같이 Flickr에서 가져옵니다. 이것은 로맹 사람에 의해 포토 스트림 응용 프로그램에서 코드를 기반으로합니다 :
InputStream in = new BufferedInputStream(url.openStream(), IO_BUFFER_SIZE);
final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
out = new BufferedOutputStream(dataStream, IO_BUFFER_SIZE);
copy(in, out);
out.flush();
final byte[] data = dataStream.toByteArray();
PS를 : 나는 또한 android.developer 구글 그룹에이 질문의 변형을 기록했다.
제안 해 주셔서 감사합니다. 지금은 정말 당황 스럽습니다. 내가 제안한 바대로 다운로드 한 바이트 배열에서 직접 생성 된 이미지가 실제로 픽셀 화 된 것을 발견했습니다. 그러나이 URL은 내 컴퓨터에서 액세스 할 때 픽셀 화되지 않은 동일한 URL에서 다운로드됩니다. 내가 시뮬레이터보다는 내 전화 (A HTC 영웅)에서 동일한 응용 프로그램을 실행할 때
http://farm3.static.flickr.com/2678/4315351421_54e8cdb8e5.jpg
심지어 낯선 사람이, 어떤 픽셀 레이션이 없다 : 여기에 해당 플리커 URL입니다.
어떻게 가능합니까? 다음은
내가 URL에서 비트 맵을로드하기 위해 사용하는 코드입니다 -이 로맹 사람에 의해 포토 스트림 응용 프로그램을 기반으로, 그것은 파일로 원시 바이트 배열을 작성하는 의지의 제안을 통합 :Bitmap loadPhotoBitmap(URL url) {
Bitmap bitmap = null;
InputStream in = null;
BufferedOutputStream out = null;
try {
FileOutputStream fos = new FileOutputStream("/sdcard/photo-tmp.jpg");
BufferedOutputStream bfs = new BufferedOutputStream(fos);
in = new BufferedInputStream(url.openStream(),
IO_BUFFER_SIZE);
final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
out = new BufferedOutputStream(dataStream, IO_BUFFER_SIZE);
copy(in, out);
out.flush();
final byte[] data = dataStream.toByteArray();
bfs.write(data, 0, data.length);
bfs.flush();
BitmapFactory.Options opt = new BitmapFactory.Options();
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, opt);
} catch (IOException e) {
android.util.Log.e(LOG_TAG, "Could not load photo: " + this, e);
} finally {
closeStream(in);
closeStream(out)
closeStream(bfs);
}
return bitmap;
}
private static void copy(InputStream in, OutputStream out) throws IOException {
byte[] b = new byte[IO_BUFFER_SIZE];
int read;
while ((read = in.read(b)) != -1) {
out.write(b, 0, read);
}
}
private static void closeStream(Closeable stream) {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
android.util.Log.e(LOG_TAG, "Could not close stream", e);
}
}
}
나는 여기서 미쳤어? 최고, 마이클.
이미지를 인라이닝하는 자유를 얻었습니다. 일반적으로 이미지를 더 멋지고 읽기 쉽게 만들어주기 때문입니다. – unwind
이것을 해결할 방법을 찾았습니까? 나는 제안을 시도했지만 운은 없다. 그것은 매우 성가신 일입니다. – blork
을 각주로 사용하십시오. 안드로이드 환경에서는 JPEG이 무손실하지 않다는 것을 잊지 마십시오. 지원되지만 PNG에 찬성하여 낙담합니다. – user836725