android - 在使用 picasso 将图片调整为 imageview 后,如何获取图片的结果位图

标签 android bitmap imageview picasso

我正在尝试调整我图库中图片的大小以适合 imageview 并在适合后保存它的位图,这样我就可以在按下“添加”按钮时将它上传到我的 Parse 数据库。目前,当按下“添加”时,我检查位图是否为空,如果不是,则将其转换为 Parsefile 以保存在我的 Parse 数据库中。添加到数据库是可行的(我在没有使用 Picasso 的情况下对此进行了测试),但是如果我使用 Picasso 调整大小和加载,我不确定如何获取位图。我尝试创建一个 Target 并使用它的回调,但我不能在目标上使用 .fit() 。我求助于使用回调,但我希望有更好的方法来实现位图的保存。

这是我现在正在做的,试图在 ImageView 加载后从 ImageView 中获取位图:

if(uri != null) {
            Picasso.with(mContext).load(uri).skipMemoryCache().fit().centerCrop().into(imgPreview, new Callback() {

                @Override
                public void onSuccess() {
                    mBitmap = ((BitmapDrawable)imgPreview.getDrawable()).getBitmap();
                }

                @Override
                public void onError() {
                    // TODO Auto-generated method stub
                }
            });
}

最佳答案

你可以使用回调

 Picasso.with(context)
    .load(absolutePath)
    .fit()
    .noFade()
    .centerInside()
    .placeholder(R.drawable.image_holder)
    .memoryPolicy(MemoryPolicy.NO_CACHE)
    .into(imageView, new Callback() {
        @Override
        public void onSuccess() {
        // You can do anything here because your imageView now has the bitmap set
        }

        @Override
        public void onError() {

        }
    });

关于android - 在使用 picasso 将图片调整为 imageview 后,如何获取图片的结果位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25322607/

相关文章:

c++ - 使用 C++ 在 Linux 中绘图并创建位图

Android 将 TextView 保持在 ImageView 内的固定位置

Android ImageView翻转动画

android - ActionBarActivity 和 ActivityUnitTest - NameNotFoundException

c# - 滚动时 Xamarin.Android 中的 ListView 内存不足

android - iOS/Android - 通过蓝牙的 TCP/IP

Android 连续拍摄 View 的屏幕截图,以便创建视频

java - 三星 Galaxy S3 中缩放位图失败

java - 无法从另一个类更改 Imageview 的图像

android - 需要帮助使用 android 显示印度城市的当前时间