개발/개발 자료

(Android) Assets에서 Bitmap 읽어오기

시원한물냉 2014. 3. 24. 17:55

public Bitmap assetsRead(String file) {
		InputStream is;
		Bitmap bitmap = null;
		
		try {
			is = mContext.getAssets().open(file);
		
		  int size = is.available();
		  byte[] buffer = new byte[size];
		  is.read(buffer);
		  is.close();
		  
		  bitmap = BitmapFactory.decodeByteArray( buffer, 0, buffer.length ) ;  
		 
		  bitmap = Bitmap.createScaledBitmap(bitmap, 300, 340, true);
		  
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		
		
		 return bitmap ;  
    }


매개변수는 파일 경로를 넣어주면 된다. 소스에 300, 340 은 비트맵 사이즈를 리사이징 하는 부분