안드로이드 개발 질문/답변
(글 수 45,052)
public Bitmap getImage() {
Bitmap bitmap = null;
try {
URL url = new URL("인터넷 그림 주소);
URLConnection conn = url.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bitmap = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
} catch (Exception e) {
Log.d("bitmap", "Errorgetting bitmap");
e.getStackTrace();
}
System.out.println("bitmap" + bitmap);
return bitmap;
}
drawable2 = this.getResources().getDrawable(getImage());
itemziedOverlay2 = new Reservation_Activityarea(drawable2, this);
이런식으로 MapActivity를 extends 시킨 클래스에서 맵에 마커를 찍으려고 합니다.
그런데 마커의 그림이 모두 다르게 하려고, copy한 이미지 대신 서버에서 매번 받으려고 하는데, 밑줄친 부분에서 에러가 뜹니다.
에러 메시지는 The method getDrawable(int) in the type Resources is not applicable for the arguments (Bitmap) 으로 bitmap이 아닌 int형 id 값을 넘기라고 나옵니다. 구글맵에 직접 받은 이미지 마커들을 찍으려는데 고수 분들 답변 부탁드립니다.
getResources() 함수는 리소스에서 이미 등록 되어있는 이미지 ID 값을 이용해를 이미지를 가져오는 함수입니다.
SDK 문서를 좀 더 살펴보세요.
BitmapDrawable bitmapDrawable = (BitmapDrawable) getImage() ;
Drawable drawable = (Drawable)bitmapDrawable;
이렇게 하시면 해당 부분은 해결 되실겁니다.