@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK){
if(requestCode == TAKE_CAMERA){
Uri currImageURI = data.getData();
}else if(requestCode == TAKE_GALLERY){
Uri currImageURI = data.getData();
Bitmap bm;
try {
bm = Images.Media.getBitmap(getContentResolver(), currImageURI);
ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
bm.compress(CompressFormat.JPEG, 100, byteArray);
byte[] byteimage = bitmapToByteArray(bm);
Sample3View s = new Sample3View(this);
//s.surfaceCreated(s.getHolder());
bm = s.processFrame_picture(byteimage, bm.getWidth(), bm.getHeight());
//이부분이 문제...
ImageView imgview = (ImageView)findViewById(R.id.imageView1);
imgview.setImageBitmap(bm);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //Bitmap 로드
}
}
}
1. 안드로이드에서 영상처리를 할때 카메라에서 받은 파일은 yuv 형식으로 알고 있습니다.
하지만 갤러리에서 가져온 파일은 rgb라는데 맞는 건가요?
2. 그리고 opencv를 이용한 프로그래밍을 하고 싶은데 ndk로 이미지를 보내려면 byte 단위 뿐인데....
갤러리에서 가져온 파일을 byte로 변환하는 방식을 좀 알려주세요 ㅜㅜ
(byte의 width와 height에 대한 정보....)
한달째 고생중입니다.. 살려주세요




우선 갤러리에서 가져온 데이터를 Bitmap으로 변경합니다.
그리고.. 제가 쓰는 소스입니다...
/**
* Bitmap에서 byte 배열을 추출한다.
* @param bitmap 원본 비트맵 이미지
* @return byte[] BGRA 데이터, 1pixel당 4byte
*/
public static byte[] extractByteArrayFromImage(Bitmap bitmap)
{
int width = bitmap.getWidth();
int height = bitmap.getHeight();
// int[] 데이터 추출(BGRA)
int [] data = new int[width * height];
bitmap.getPixels(data, 0, width, 0, 0, width, height);
return convertIntArrayToByteArray(data, width, height);
}
/**
* 1픽셀당 4Byte를 Integer로 되어있는 것을 Byte로 변환
* @param rgb 1픽셀당 4Byte(int)로 된 픽셀 데이터 배열
* @param width
* @param height
* @return
*/
public static byte[] convertIntArrayToByteArray(int[] rgb, int width, int height){
try {
// the size of the BMP file in bytes
int fileSize = height * width * 4;
ByteArrayOutputStream bytes = new ByteArrayOutputStream(fileSize);
DataOutputStream out = new DataOutputStream(bytes);
int colorValue = 0;
for (int j = height - 1; j >= 0; j--) {
for (int i = 0; i < width; i++) {
colorValue = rgb[i + width * j];
out.writeByte(colorValue & 0x000000FF);
out.writeByte((colorValue >>> 8) & 0x000000FF);
out.writeByte((colorValue >>> 16) & 0x000000FF);
out.writeByte((colorValue >>> 24) & 0x000000FF);
}
}
byte[] encodeBytes = bytes.toByteArray();
bytes.close();
return encodeBytes;
} catch (IOException e) {
return null;
}
}