마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

카메라 해상도 질문드립니다.

0 추천
이진화 한 영상을 확인하기 위해서 파일 저장을 했는데 아무 이미지 표시가 안되길래 확인을 해보니
해상도가  -1 x -1 이더군요
하지만 코드상에서 BItmap.getWidth와 getHeight가 각각 1920 과 1080으로 잘 나오고
그 객체를 Bit라 할 때

/*90도 돌리기*/
Matrix mat = new Matrix();
mat.postRotate(90);
Bit = Bit.createBitmap(Bit, 0, 0, Bit.getWidth(), Bit.getHeight(), mat, true);

/* 경로 설정 */
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File file = new File(path, "test"+String.valueOf(test++)+".png");//test는 int형 변수로 여러개를 번호대로 저장함

FileWriter write = new FileWriter(file, false);
PrintWriter outp = new PrintWriter(write);

outs = new FileOutputStream(file);
Bit.compress(Bitmap.CompressFormat.PNG, 100, outs);
outp.println(Bit);
outp.close();
write.close();

이런식으로 저장합니다.

혹시 몰라 전체 코드 올리겠습니다.
==========================================================
 public void Binarization(final Camera mCamera/*, final SurfaceHolder mHolder*/) {
        // TODO Read me
        // 해상도 문제가 있음.
        // 저장은 되지만 -1 x -1 크기

        final Camera finalMCamera = mCamera;
        mCamera.setPreviewCallback(new Camera.PreviewCallback() {
            public void onPreviewFrame(byte[] data, Camera camera) {
                Camera.Parameters params = finalMCamera.getParameters();

                int w = params.getPreviewSize().width;
                int h = params.getPreviewSize().height;

                params.setPictureSize(w, h);
                mCamera.setParameters(params);

                int format = params.getPreviewFormat();

                YuvImage image = new YuvImage(data, format, w, h, null);

                Log.d("Tag", "w: "+String.valueOf(w)+"\nh: "+String.valueOf(h));
                ByteArrayOutputStream out = new ByteArrayOutputStream();

                Rect area = new Rect(0, 0, w, h);

                image.compressToJpeg(area, 50, out);

                Bitmap Bit = BitmapFactory.decodeByteArray(out.toByteArray(), 0, out.size()).copy(Bitmap.Config.ARGB_8888, true);
                Bitmap original = Bit;

                for (int i = 0; i < data.length; i += 2) {
                    if (i % Bit.getWidth() % 2 == 1) continue;
                    if (i / Bit.getWidth() >= Bit.getHeight()) break;

                    int pixel = Bit.getPixel(i % Bit.getWidth(), i / Bit.getWidth());
                    int a = Color.alpha(pixel);
                    int r = Color.red(pixel);
                    int g = Color.green(pixel);
                    int b = Color.blue(pixel);

                    if (pixel > 1073741823.5) {
                        Bit.setPixel(i % Bit.getWidth(), i / Bit.getWidth(), 2147483647);
                    } else {
                        Bit.setPixel(i % Bit.getWidth(), i / Bit.getWidth(), 1);
                    }
                }

                OutputStream outs = null;

                try {
                    Matrix mat = new Matrix();
                    mat.postRotate(90);
                    Bit = Bit.createBitmap(Bit, 0, 0, Bit.getWidth(), Bit.getHeight(), mat, true);
                
                    File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
                    File file = new File(path, "test"+String.valueOf(test++)+".png");

                    FileWriter write = new FileWriter(file, false);
                    PrintWriter outp = new PrintWriter(write);;

                    outs = new FileOutputStream(file);
                    Bit.compress(Bitmap.CompressFormat.PNG, 100, outs);
                    outp.println(Bit);
                    outp.close();
                    write.close();

                    Log.d("Tag", "release");

                    MediaScanner scanner = MediaScanner.newInstance(MainActivity.this);
                    scanner.mediaScanning(getApplicationContext().getFilesDir().getPath().toString()+"test.png");

                } catch (IOException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                    Toast.makeText(getApplicationContext(), "file error", Toast.LENGTH_LONG).show();
                    Log.d("Tag", "error");
                    e.printStackTrace();
                } finally {
                    return;
                }
            }
        });
    }
익명사용자 님이 2017년 1월 31일 질문
2017년 1월 31일 수정

1개의 답변

0 추천
MATCH_PARENT 값이 -1 인데. 이 값이 반환된 것으로 생각됩니다.

반횐되는 값이 MATCH_PARENT 일 경우 화면의 사이즈를 설정하는 코드를 추가 하시는게 좋을 듯 합니다.
익명사용자 님이 2017년 1월 31일 답변
...