카메라 어플 안에서 이미지를 돌리려고


바이트 배열(카메라 사진 데이터)을 비트맵으로 전환

↓

비트맵을 회전

↓

회전된 비트맵을 배열로 다시 전환

↓

저장


으로 하려고 코드를 짜는데 DDMS에서 저장된 이미지를 보니 이미지는 있는데 크기가 0입니다.


코드를 이곳 저곳에서 뜯어와서 약간 더러워도 이해해 주세요..


(하이라이터가 동작이 안됩니다. -모두 첫번째 행으로 나옴-


public Bitmap byteArrayToBitmap( byte[] $byteArray ) {  //바이트 배열을 비트맵으로 전환

   Bitmap bitmap = BitmapFactory.decodeByteArray( $byteArray, 0, $byteArray.length );

   rotate(bitmap, 90);

   return bitmap;

}

public static Bitmap rotate(Bitmap b, int degrees) { //비트맵 파일을 회전시키기

        if ( degrees != 0 && b != null ) {

            Matrix m = new Matrix();

            m.setRotate( degrees, (float) b.getWidth() / 2, (float) b.getHeight() / 2 );

            try {

                Bitmap b2 = Bitmap.createBitmap( b, 0, 0, b.getWidth(), b.getHeight(), m, true );

                if (b != b2) {

                    b.recycle();

                    b = b2;

                }

            } catch (OutOfMemoryError ex) {

                // 메모리가 없을 때 오리지날 비트맵으로.

            }

        }

        return b;

    }

public byte[] bitmapToByteArray( Bitmap $bitmap ) { //바이트 배열을 다시 비트맵으로

        ByteArrayOutputStream stream = new ByteArrayOutputStream() ;  

        $bitmap.compress( CompressFormat.JPEG, 100, stream) ;  

        byte[] byteArray = stream.toByteArray() ;  

        return byteArray ;  

    }  


public int SaveImage() {//이미지 저장


int ret = 0;

try {

File path = new File(mFileimageRoute+getRealFileName()+".jpg");

FileOutputStream fos = new FileOutputStream(path);

Bitmap bitmap = byteArrayToBitmap(mImageData[0]);//비트맵으로 변환

rotate(bitmap, 90);//회전

mImageData[0] = bitmapToByteArray(bitmap);


fos.write(mImageData[0]);

fos.flush();

fos.close();

System.gc();

bitmap.recycle();//비트맵 리사이클

}

    catch (FileNotFoundException fne) 

            {

            Log.e("writing and scanning image ", fne.toString());

            fne.printStackTrace();

            ret = -1;

                } 

                catch (IOException ioe) 

                {

            Log.e("writing and scanning image ", ioe.toString());

            ioe.printStackTrace();

            ret = -1;

            } catch (Exception e) 

            {

            ret = -1;

            }


return ret;


}