ImageView中的图像显示不正确

4

我创建了一个安卓应用程序,在其中我想在圆形的图像视图中显示图像。

但是图像无法正确显示在图像视图中。

我的代码如下-

int rounded_value = 168;
DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisc(true).displayer(new RoundedBitmapDisplayer(rounded_value)).build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).defaultDisplayImageOptions(options).build(); 
ImageLoader.getInstance().init(config);
ImageLoader.getInstance().displayImage(photourl, imageView, options);

例如-
原始图片尺寸为168*168。 168*168 我得到的输出是-ImageView尺寸为85*85。 85*85 我希望的输出是- 85*85

1
尝试使用这个自定义ImageView https://github.com/vinc3m1/RoundedImageView - Biraj Zalavadia
@BirajZalavadia 怎么获取 RoundedImageView.jar 文件。 - Anjali Pandya
@AnjaliPandya 不需要使用它。看看我的答案https://dev59.com/wGMl5IYBdhLWcg3we203#18378873 - Piyush
你能分享一下你想要制作的截图吗? - CompEng
@ErsinGülbahar,请查看我编辑过的问题。 - Anjali Pandya
我不是为了问题点赞,而是为了图片。 - lelloman
3个回答

0

试试这个,对我来说有效

public static Bitmap getCroppedBitmap(Bitmap bmp, int radius)
{
    Bitmap sbmp;
    if (bmp.getWidth() != radius || bmp.getHeight() != radius)
        sbmp = Bitmap.createScaledBitmap(bmp, radius, radius, false);
    else
        sbmp = bmp;
    Bitmap output = Bitmap.createBitmap(sbmp.getWidth(), sbmp.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xffa19774;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(sbmp.getWidth() / 2 + 0.7f, sbmp.getHeight() / 2 + 0.7f, sbmp.getWidth() / 2 + 0.1f, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(sbmp, rect, rect, paint);

    return output;
}

0

用户遮罩图像视图:http://goo.gl/w2LrM0

在图像视图的XML声明中提供遮罩,作为椭圆形状的可绘制XML。

无需将图像裁剪为圆形。

布局中的图像视图小部件:

<com.android.BezelImageView
// required properties, to getexact circle height should be equat to width
 app:maskDrawable="@drawable/round_mask" />

round_mask.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="oval">
           <solid android:color="#000000" />
        </shape>
    </item>
</layer-list>

0

此函数返回一个经过四舍五入和裁剪的位图

public Bitmap getCroppedBitmap(Bitmap bitmap) {
        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
                bitmap.getHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(output);

        final int color = 0xff424242;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);
        // canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
        canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
                bitmap.getWidth() / 2, paint);
        paint.setXfermode(`n`ew PorterDuffXfermode(Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);
        // Bitmap _bmp = Bitmap.createScaledBitmap(output, 60, 60, false);
        // return _bmp;
        return output;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接