Can't create handler inside thread that has not called Looper.prepare() 에러발생시 해결방법 Thread나 Handler사용하다보면 아래과 같은 에러가 발생하면서 죽어버리는 경우가 종종발생합니다. Can't create handler inside thread that has not called Looper.prepare() 예를들어 아래와 같은 코드를 사용하였는데 위와같은 에러가 뜨면서 죽는다.new Thread(new Runnable() {public void run() {new Handler().postDelayed(new Runnable() {public void run() {//하고싶은 작업추가}}, 30);}}).start(); 그럼 밑에 ..
내/외장에 저장 된 이미지 파일(PNG or JPEG ...)을 Bitmap으로 읽어 들이는 간단한 코드이다. 이미지 파일을 읽을 때 너무 큰 이미지는 OutOfMemory가 발생한다. 그래서 폰의 화면 해상도에 가장 근접하게 리스케일을 하여 읽어들이게 했다. 코드는 아주 간단하다. /** * 지정한 패스의 파일을 읽어서 Bitmap을 리턴 (화면사이즈에 최다한 맞춰서 리스케일한다.) * * @param context * application context * @param imgFilePath * bitmap file path * @return Bitmap * @throws IOException */public static Bitmap loadBackgroundBitmap(Context context, ..
Android에서 사용하는 이미지는 Bitmap이라는 클래스에서 다~ 알아서 해줍니다. 그리고 이런 Bitmap Object를 쉽게 만들 수 있도록 도와주는 BitmapFactory 클래스 라는 것도 있습니다. BitmapFactory는 여러가지 소스로 부터 Bitmap Object를 만들어 주는 일을 하는데, 전부 static이며 decodeXXX 라는 이름을 가진 메소드들로 이루어져 있습니다.XXX에는 어떤 것으로 부터 decode를 하여 Bitmap Object를 만들어 낼지에 대한 말들이 들어 가겠죠. [Decoding Methods] BitmapFactory.decodeByteArray() 메소드는 Camera.PictureCallback 으로 부터 받은 Jpeg 사진 데이터를 가지고 Bitma..
Bitmap 이미지를 byte[] 로 가져 오거나 byte[] 을 Bitmap 으로 만드는 방법이다. //Bitmap -> Byte[]ByteArrayOutputStream bytearray = new ByteArrayOutputStream();ImageIO.write(image, "png", bytearray);byte[] b = bytearray.toByteArray(); public byte[] bitmapToByteArray( Bitmap bitmap ) { ByteArrayOutputStream stream = new ByteArrayOutputStream() ; bitmap.compress( CompressFormat.JPEG, 100, stream) ; byte[] byteArray = st..