【问题标题】:How do I get the resulting bitmap of a picture after it has been resized into an imageview with picasso使用毕加索将其大小调整为图像视图后,如何获取图片的结果位图
【发布时间】:2014-10-08 23:08:24
【问题描述】:

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

这就是我现在正在做的事情,试图在加载后从图像视图中获取位图:

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

【问题讨论】:

  • 是的,我在发布之前看到了这个答案,但是您不能将 .fit() 与目标一起使用。似乎这样做只能存储原始图像,但我希望能够在调用 .fit() 后使用回调来存储位图。我在我的问题中说明了这一点:“我尝试创建一个目标并使用它的回调,但我不能在目标上使用 .fit()。”

标签: android bitmap imageview picasso


【解决方案1】:

你可以使用回调

 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() {

        }
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-21
    • 1970-01-01
    • 2016-02-02
    • 2016-03-07
    • 1970-01-01
    • 2012-07-28
    • 1970-01-01
    • 2014-08-15
    相关资源
    最近更新 更多