메뉴 건너뛰기

조회 수 7058 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

웹에 떠있는 이미지를 가져온다. 말 그대로 그냥 저장된 이미지만 가져오면 되므로 이번 소스는 매우 쉽다.

 

먼저 PictureClass 에서 만들것인데,, 그클래스를 불러오는 로직을 보면 아래와같다.

클래스내부의 홈페이지 루트를 넣어준다.

 

 

PictureClass picture=new PictureClass("내가원하는 홈페이지");

//현재 에서 Context를 받아옴

final ImageView iv=new ImageView(getApplicationContext());

//넓이와 높이고정 

iv.setScaleType(ImageView.ScaleType.FIT_XY);

//실제이미지 크기설정 

if(picture.getRemoteImage(phoneNum)!=null)

//이부분에서는 getRemoteImage(파일이름)을 사용하여 불러오도록 한다.

iv.setImageBitmap(picture.getRemoteImage(파일이름));

else  //파일이 없을 경우를 대비해서 다른 소스 넣기

iv.setImageResource(R.drawable.ic_launcher);

 

그럼이제 PictureClass를 살펴보도록 하겠다. 여기도 역시나 간단하다. 

 

 

 

PictureClass.java

 

 

public class PictureClass{

//파일이 존재하는곳 root는 홈페이지 주소이다. 

private static String root;

public PictureClass(String root1){

root=root1;

}

Bitmap getRemoteImage(String imageName){

//시작 비트맵을 넣어주고 

Bitmap bitmap=null;

try{

//현재 그림이있는곳으로이동해서 URL생성한다. 

URL url=new URL(root+imageName+".png");

//URL에 연결하는과정 

URLConnection conn=url.openConnection();

conn.connect();

//이미지를 가지고 와서 decodeStream()메소드로  Bitmap이미지 만들기 

BufferedInputStream bis=new 

BufferedInputStream(conn.getInputStream());

bitmap=BitmapFactory.decodeStream(bis);

bis.close();

}catch(IOException e){

e.printStackTrace();

}

return bitmap;

}

}

 

간단하다..그냥 그림 가져오는 걸 너무복잡하게생각한것같다.. 그림 내려받기는 정말어렵지 않구나,,,

다음은 FTP 를 이용해서 이미지 업로드 작업을 해야겠다.


  1. 안드로이드 웹에서 이미지 불러오기!!

    Date2014.08.28 Views7058
    Read More
  2. 안드로이드 android 개발 와이파이 유지 관련

    Date2015.07.16 Views7048
    Read More
  3. [안드로이드] 버튼 이벤트 처리하기

    Date2015.07.17 Views7036
    Read More
  4. 푸시 서비스(GCM)에 대해 알아보자

    Date2015.07.01 Views7006
    Read More
  5. [안드로이드] 레이아웃의 기본1

    Date2015.07.16 Views6971
    Read More
  6. 옵션 메뉴 동적으로 생성하기

    Date2015.07.16 Views6933
    Read More
  7. Android] 안드로이드 홈 디렉토리 알아내기

    Date2015.12.15 Views6906
    Read More
  8. 내가 입력한 글자 Toast로 나오게 하기

    Date2015.07.26 Views6905
    Read More
  9. android SMS 리시버

    Date2015.06.29 Views6871
    Read More
  10. [안드로이드 강좌] 초보자들이 많이 하는 실수

    Date2015.08.11 Views6837
    Read More
  11. HTML5 Geolocation (구글 지도에 현위치 표시하기)

    Date2014.09.04 Views6814
    Read More
  12. [안드로이드] 빠르게 사용할수 있는 컨텍스트 메뉴 만들기

    Date2015.09.03 Views6809
    Read More
  13. 특정 폴더에서 오래된 파일 삭제하기

    Date2015.07.16 Views6780
    Read More
  14. [안드로이드] Activity에 대해서

    Date2015.07.16 Views6768
    Read More
  15. CSS3 Rounded Corner, 그림자 효과 사용하기

    Date2014.09.04 Views6767
    Read More
  16. Effects - SlideToggle() 메서드 (슬라이드 업/다운)

    Date2014.10.16 Views6763
    Read More
  17. ImageVeiw의 현재 리소스 비교하기

    Date2014.08.28 Views6756
    Read More
  18. 푸쉬 알림 기능. GCM (Google Cloud Messaging) 사용하기 (1)

    Date2015.07.16 Views6730
    Read More
  19. 트리뷰(TreeView) 컨트롤

    Date2014.10.16 Views6727
    Read More
  20. jQuery ajax post 요청 text 응답

    Date2014.10.16 Views6710
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 13 Next
/ 13

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved