CenterCrop无法在通用图像加载器中运行:Android

May*_*ara 5 android imageview universal-image-loader scaletype

我目前正在使用Universal Image Loader 1.9.3并将其初始化为,

DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder().displayer(new RoundedBitmapDisplayer(100)).cacheOnDisc().build();
    ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(Register.this).defaultDisplayImageOptions(defaultOptions).memoryCache(new WeakMemoryCache());

    ImageLoaderConfiguration config = builder.build();
    imageLoader2 = ImageLoader.getInstance();
    imageLoader2.init(config);
Run Code Online (Sandbox Code Playgroud)

在这里我使用了RoundedBitmapDisplayer,因为我希望图像为圆形,并且我已将xml文件中的图像视图属性设置为android:scaleType ="centerCrop",因此它必须将结果作为中心裁剪图像,但它不会给出中心裁剪图像..图像被拉伸甚至给中心作物....

She*_*han 1

是的,有人提到它总是保持纵横比,而改变 xml 上的scaletype属性是行不通的......使用编码作物代替

public static Bitmap toCropcenterfitoriginal(Bitmap srcBmp) {
    Bitmap dstBmp = ThumbnailUtils.extractThumbnail(srcBmp,
            srcBmp.getWidth() / 2, srcBmp.getWidth() / 3);
    ;

    return dstBmp;
}
Run Code Online (Sandbox Code Playgroud)