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

안드로이드 firebase 비트맵 ImageView 설정 질문.

0 추천
private void galleryAddPic()
    {

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

        final Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);

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

        onWindowFocusChanged(true);

        int targetW = imageViewW;
        int targetH = imageViewH;

        // Get the dimensions of the bitmap
        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;

        //Toast.makeText(this, String.valueOf(scaleFactor), Toast.LENGTH_SHORT).show();

        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);

        // ------------------------------------------------------------- image Upload

       /**/ 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");

                    }
                });
    }

  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;
                            onWindowFocusChanged(true);
                            setImageFile(intent);

                        }
                    }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception exception) {
                    // Handle failed download
                    // ...
                }
            });

           /* pathReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                @Override
                public void onSuccess(Uri uri) {
                    // Got the download URL for 'users/me/profile.png'

                    Toast.makeText(MainActivity.this, "Download Success", Toast.LENGTH_SHORT).show();
                    Log.i("File Download","Download Success");
                    imageDownload = true;
                    onWindowFocusChanged(true);
                    setImageFile(intent);

                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception exception) {
                    // Handle any errors
                }
            });

           */
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

 public void setImageFile(Intent intent)
    {
        Log.i("setImage","setImageFile Start");

        if(imageDownload == true)
        {
            // imageView.setImageBitmap(bitmap);
            imageView.setImageBitmap(rotate(bitmap, exifDegree));
            Toast.makeText(this, String.valueOf(bitmap), Toast.LENGTH_SHORT).show();

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

1개의 답변

0 추천
칸이 모자라서 여기다가 작성하겠습니다..

 

코드는 위와 같습니다. 그런데 이 코드가 작동을 하다가도 , 어쩔때는 download를 받고서

setIamgeFile() 메소드를 호출하고 imageView.setImageBitmap(rotate(bitmap, exifDegree)); 를 실행했음에도

불구하고 imageView에 사진이 올라가질 않는데; 왜그러는 건지 이유를 모르겠습니다.

안될려면 아예안되던가.. 됬다가 안됬다가 하니 미칠 것 같습니다..

메모리 문제인 것 같기도 한데; ..

 

답변 부타드리겠습니다.
알파고 (4,320 포인트) 님이 2017년 9월 11일 답변
이미지 사이즈가 해당 디바이스에서 지원하는 최대 크기를 넘어설 경우 아예 표시되지 않습니다.
insamplesize의 스케일 팩터를 조정해보세요
insampleSize가 문제가 아니라 뭔가 잘못된 것 같습니다;; 잘되다가 안되다가를 반복해요 Log에도 별 문제없구요 정상작동 하는 것 처럼보입니다; 그런데 정말 이해가 안가는게 왜 잘되다가 다음날 다시 해보면 또 안되는 겁니다;

정말 왜그럴까요 ㅠㅠ?
...