자료
URL주소의 이미지를 Bitmap으로
사진미소
2011. 7. 13. 09:50
URL주소의 문자열을 이미지로 표시 할때 png는 잘 표시 되는데 가끔 JPG가 표시가 안되는 문제가 있었다.
로그를 보니...
skia decoder- decode returned false
이런게 뜨던데....
이미지를 다 받기전에 디코더를 닫아버리는데서 발생하는 문제라단 -구글신-
검색해서 기존에 내가 사용하던 메쏘드에 조금 추가해서 아래와 같이 만들었다.
잘된다 ㅋㅋㅋ
/**
* 문자열 URL의 주소를 bitmap으로 변환 후 반환
* @param _photoURL : 이미지http문자열
* @param _size : n/1사이즈 설정
* @return
*/
public static Bitmap urlTobitmap(String _photoURL, int _size) {
URL url = null;
Bitmap bitmap = null;
try {
url = new URL(_photoURL);
HttpGet httpRequest = null;
try {
httpRequest = new HttpGet(url.toURI());
} catch (Exception e) {
e.printStackTrace();
}
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient
.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
InputStream instream = bufHttpEntity.getContent();
bitmap = BitmapFactory.decodeStream(instream);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bitmap;
}
로그를 보니...
skia decoder- decode returned false
이런게 뜨던데....
이미지를 다 받기전에 디코더를 닫아버리는데서 발생하는 문제라단 -구글신-
검색해서 기존에 내가 사용하던 메쏘드에 조금 추가해서 아래와 같이 만들었다.
잘된다 ㅋㅋㅋ
/**
* 문자열 URL의 주소를 bitmap으로 변환 후 반환
* @param _photoURL : 이미지http문자열
* @param _size : n/1사이즈 설정
* @return
*/
public static Bitmap urlTobitmap(String _photoURL, int _size) {
URL url = null;
Bitmap bitmap = null;
try {
url = new URL(_photoURL);
HttpGet httpRequest = null;
try {
httpRequest = new HttpGet(url.toURI());
} catch (Exception e) {
e.printStackTrace();
}
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient
.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
InputStream instream = bufHttpEntity.getContent();
bitmap = BitmapFactory.decodeStream(instream);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bitmap;
}