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

안드로이드 사진 리사이즈 시에 [closed]

0 추천

private void galleryAddPic()
    {

        Toast.makeText(this,"gelleyAddPic", Toast.LENGTH_SHORT).show();
        Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_SHORT).show();

        Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);

        File file = new File(mCurrentPhotoPath);
        contentUri = Uri.fromFile(file);
        intent.setData(contentUri);

        int targetW = imageView.getWidth();
        int targetH = imageView.getHeight();

        // Get the dimensions of the bitmap
        BitmapFactory.Options bmOptions = new BitmapFactory.Options();
        bmOptions.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
        int photoW = bmOptions.outWidth;
        int photoH = bmOptions.outHeight;

        // Determine how much to scale down the image
        int scaleFactor = Math.min(photoW/targetW, photoH/targetH);<- 여기서 자꾸 에러가 발생합니다.

        // Decode the image file into a Bitmap sized to fill the View
        bmOptions.inJustDecodeBounds = false;
        bmOptions.inSampleSize = scaleFactor;
        bmOptions.inPurgeable = true;

        Log.i("scaleFactor", String.valueOf(scaleFactor));
        Toast.makeText(this, String.valueOf(scaleFactor), Toast.LENGTH_SHORT).show();

        ExifInterface exif = null;

        try {
            exif = new ExifInterface(mCurrentPhotoPath);
        } catch (IOException e) {
            e.printStackTrace();
        }
        int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        int exifDegree = exifOrientationToDegrees(exifOrientation);


        bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
       // imageView.setImageBitmap(bitmap);
        imageView.setImageBitmap(rotate(bitmap, exifDegree));
        sendBroadcast(intent);

 

-------------------------------------------------------------------------------------------------------------

W/System.err: java.lang.ArithmeticException: divide by zero 라는 에러가 발생되는데요, 

이 에러가 발생할때가 있고 안될때가 있습니다. 왜 이런 현상이 이러나는지 도저히 모르겠습니다 ㅠㅠ

답변 부탁드리겠습니다..!

-------------------------------------------------------------------------------------------------------------

Log 찍어서 확인해본 결과

 int targetW = imageView.getWidth();

 int targetH = imageView.getHeight();

부분이 둘다 값이 0으로 확인되었습니다. 그런데 왜 그런건지;;..

잘될때가있고 안될때도 있고;; 

질문을 종료한 이유: 해결했습니다. 안드로이스 시스템 설계상 onCreate에 imageView를 만들어놨더라도 메모리에는 올라가더라도 실제로 그려지지는않았더라는 문제입니다. 그래서 호출 시점을  onWindowFocusChanged(boolean hasFocus) 이렇게 해주면 바로 이 시점이 컴포넌트들을 그리기 시작하는 단계이기 때문에 0이 아닌 올바른 값을 얻을 수 있었습니다.
알파고 (4,320 포인트) 님이 2017년 9월 8일 질문
알파고님이 2017년 9월 8일 closed
...