본문 바로가기
안드로이드

안드로이드 - 인터넷의 이미지를 비트맵 타입으로 변경하고 사이즈 조절하기

by leo104 2023. 2. 15.
728x90

1. URL 이미지 객체화

 
 
 
<java />
 
URL urlImg = new URL("URL주소");

 

2. URL 이미지를 비트맵 타입으로 변경

 
 
 
<java />
 
Bitmap urlBitMap = BitmapFactory.decodeStream(urlImg.openConnection().getInputStream());

 

3. 비트맵 타입의 이미지 사이즈 변경

  • Bitmap.createScaledBitmap( "resource" , " width", "height" , "filter" )
 
 
 
<java />
 
Bitmap resizeBitmap = Bitmap.createScaledBitmap( "비트맵객체명" ,100, 150, false );

 

4. 응용) URL 이미지를 이미지 변경하여 객체화

 
 
 
<java />
 
URL urlImage = new URL("urlString");
Bitmap posterImg = Bitmap.createScaledBitmap(
		BitmapFactory.decodeStream(urlImage.openConnection().getInputStream() ),
        100, 150, false);

 

728x90