使用Picasso将图像加载到文件中的活动结果。

时间:2016-08-03 21:54:42

标签: android picasso

我有一个活动试图在其onActivtyResult方法中调用以下方法

private void loadTempFile(Uri originalImgUri) {
    final Target target = new Target() {
        @Override
        public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
            try {
                String state = Environment.getExternalStorageState();
                String absolutePath = getFilesDir().getAbsolutePath();

                if (Environment.MEDIA_MOUNTED.equals(state)) {
                    absolutePath = PhotoUtils.getFilesPath(getApplicationContext());
                }

                // If the output directory for the file isn't there, we make it
                File outputDirectory = new File(absolutePath);
                if (!outputDirectory.exists()) {
                    outputDirectory.mkdirs();
                }

                tempPhotoUri = absolutePath + "/temp.jpg";
                tempPhoto = new File(tempPhotoUri);
                tempPhoto.createNewFile();
                Timber.d(String.format("Upload temp file created: %s", tempPhoto.exists()));

                FileOutputStream ostream = new FileOutputStream(tempPhoto);
                bitmap.compress(Bitmap.CompressFormat.JPEG, 100, ostream);
                ostream.close();
            } catch (Exception e) {
                Timber.d(e.getMessage());
            }
        }
        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {
        }
    };

    Picasso.with(PhotoUploadActivity.this)
            .load(originalImgUri)
            .resize(RESIZE_IMAGE_DIMENSION, RESIZE_IMAGE_DIMENSION)
            .noPlaceholder()
            .onlyScaleDown()
            .centerCrop()
            .into(target);
}
永远不会调用

onBitmapLoaded。有什么建议吗?

我已经尝试将目标移到课堂上,基本上在其他地方....

0 个答案:

没有答案