Skip to content

glide 图片居中问题 #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
seefutureLee opened this issue Sep 5, 2019 · 7 comments
Closed

glide 图片居中问题 #218

seefutureLee opened this issue Sep 5, 2019 · 7 comments

Comments

@seefutureLee
Copy link

glide 适配图片有问题 imageview设置的fitxy 但是展示出来过小的图片 就跑到左上角了

@mawenjie1234
Copy link

应该和fitxy没什么关系。

@mawenjie1234
Copy link

bitmap 创建需要传DisplayMetrics,你可以在你glide 的transform 里面写。
Bitmap bmpGrayscale = Bitmap.createBitmap(getContext().getResources().getDisplayMetrics(),
width, height, config);

@seefutureLee
Copy link
Author

👌

@zhuzhushang
Copy link

@mawenjie1234 我这是用glide的设置圆角才有这个问题,跟踪代码,是在transform方法中这行代码改变的density,
image
这行代码是Glide的,不知道用什么方法改

Bitmap bmpGrayscale = Bitmap.createBitmap(getContext().getResources().getDisplayMetrics(),
width, height, config);

glide代码:

    @NonNull
    public Bitmap get(int width, int height, Config config) {
        Bitmap result = this.getDirtyOrNull(width, height, config);
        if (result != null) {
            result.eraseColor(0);
        } else {
            result = Bitmap.createBitmap(width, height, config);
        }

        return result;
    }

@JessYanCoding
Copy link
Owner

JessYanCoding commented Aug 24, 2021

你重新 createBitmap 个新的 bitmap,宽高和内容都 copy 一下 pool.get() 获取的这个 bitmap 就可以了,对 bitmap 的备份,网上教学内容很多

@zhuzhushang
Copy link

@JessYanCoding 因为我这边发现是在transform方法中调用了
Bitmap result = pool.get(toTransform.getWidth(), toTransform.getHeight(), Bitmap.Config.ARGB_8888); 方法后改变了bitmap的density,但是宽高并没有变化,所以我这里直接调用了bitmap的setdensity方法
result.setDensity(getResources().getDisplayMetrics().densityDpi);
目前还没发现问题。

@MaryDQ
Copy link

MaryDQ commented Jun 6, 2023

兄弟,你这个方案现在没有效果啊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants