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

안드로이드 비트맵 이미지뷰 안보이는 문제

0 추천
public void Camera()
    {

        String state = Environment.getExternalStorageState();

        if(Environment.MEDIA_MOUNTED.equals(state))
        {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

            if(intent.resolveActivity(getPackageManager()) != null)
            {
                File photoFile = null;

                try
                {
                    photoFile = createImageFile();
                }
                catch(IOException e)
                {
                    Toast.makeText(this, "Camera Error", Toast.LENGTH_SHORT).show();
                }

                if(photoFile != null)
                {
                    Uri providerUri = FileProvider.getUriForFile(this, getPackageName()+".fileprovider", photoFile);
                    imageUri = providerUri;

                    intent.putExtra(MediaStore.EXTRA_OUTPUT, providerUri);

                    startActivityForResult(intent, REQUEST_CAMERA);
                }
            }
            else
            {
                Toast.makeText(this, "None createImageFile", Toast.LENGTH_SHORT).show();
            }
        }
        else
        {
            Toast.makeText(this, "저장 공간 접근 불가", Toast.LENGTH_SHORT).show();
            return;
        }
------------------
  private File createImageFile() throws IOException
    {

        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        imageFileName = timeStamp + ".jpg";

        imageFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/image/"+imageFileName);

        if(!imageFile.exists())
        {
            imageFile.getParentFile().mkdirs();
            imageFile.createNewFile();
        }

        mCurrentPhotoPath = imageFile.getAbsolutePath();
        Toast.makeText(this, "mCurrentPhotoPath", Toast.LENGTH_SHORT).show();
        Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_SHORT).show();

        return imageFile;
    }
------------------------------------

    private void galleryAddPic()
    {
        final Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);

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

        Log.i("Upload", "Upload Start");

        storageRef = storage.getReferenceFromUrl("gs").child("images/"+imageFileName);

        storageRef.putFile(contentUri)
                .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

                        @SuppressWarnings("VisibleForTests") Uri downloadUrl = taskSnapshot.getDownloadUrl();

                        downloadImageFile(intent);

                        Log.i("File Upload","File Upload Success");
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception exception) {

                        Log.i("File Upload","File Upload Failed");

                    }
                });

        Toast.makeText(this, "사진 저장 완료", Toast.LENGTH_SHORT).show();
    }
-------------------------------------------
private void downloadImageFile(final Intent intent)
    {
        StorageReference gsReference = storage.getReferenceFromUrl("gs");
        StorageReference pathReference = gsReference.child("images/"+imageFileName);

        try
        {
            File localFile = File.createTempFile("images", "jpg");

            pathReference.getFile(localFile)
                    .addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
                        @Override
                        public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {

                            Toast.makeText(MainActivity.this, "Download Success", Toast.LENGTH_SHORT).show();
                            Log.i("Download", "Download Success");

                            imageDownload = true;
                            setImageFile(intent);

                        }
                    }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception exception) {
                    // Handle failed download
                    // ...
                }
            });
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
-------------------------------------------------------
 public void setImageFile(Intent intent)
    {

        if(imageDownload == true)
        {
            bmOptions = new BitmapFactory.Options();
            bmOptions.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);

            int photoW = bmOptions.outWidth;
            int photoH = bmOptions.outHeight;

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

            int scaleFactor = Math.min(photoW/targetW, photoH/targetH);

            bmOptions.inJustDecodeBounds = false;
            bmOptions.inSampleSize = scaleFactor;
            bmOptions.inPurgeable = true;

            ExifInterface exif = null;

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

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

            if(bitmap != null)
            {
                Toast.makeText(this, "butmap memory release", Toast.LENGTH_SHORT).show();

                bitmap.recycle();
                bitmap = null;
            }

            imageDownload = false;
            sendBroadcast(intent);
        }
    }
알파고 (4,320 포인트) 님이 2017년 9월 16일 질문
알파고님이 2017년 9월 17일 수정

1개의 답변

0 추천
 
채택된 답변
이해가 안가는게 앱이 잘 작동하다가 또 잘안된다는 겁니다... 이미지 크기 때문도 아닌 것 같구요 insampleSize 수정해봤습니다.. 도대체 뭐가 문제 이길래 잘 되다가 안되는지 모르겠습니다..

 

단순히 제 기기(갤럭시s4) 문제인지; avd는 문제가 없거든요

도대체 왜 됬다가 안됬다가를 반복할까요 ????

답변 부탁드립니다!!!
알파고 (4,320 포인트) 님이 2017년 9월 16일 답변
알파고님이 2017년 10월 11일 채택됨
...