gpt4 book ai didi

android - 以圆形显示图像

转载 作者:行者123 更新时间:2023-11-30 02:55:44 25 4
gpt4 key购买 nike

我正在从服务器获取图像,它们是正方形的。但是我想在我的应用程序中将它们显示在一个圆圈中。我已经通过制作圆形 Drawable 来尝试它。但它不起作用。谁能建议我如何做到这一点。我将不胜感激任何帮助。谢谢。

最佳答案

试试下面的代码:-

Universal loader

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()).defaultDisplayImageOptions(options)
.build();
ImageLoader.getInstance().init(config);

DisplayImageOptions options1 = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisc(true).displayer(new RoundedBitmapDisplayer(60)).build();
ImageLoader.getInstance().displayImage(Uri.parse(imgByURL).toString(), imgThumb, options);

imageViewUser.setImageBitmap(getCircleBitmap(bitmap));


import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
public Bitmap getCircleBitmap(Bitmap bitmap)
{
Bitmap output;
Canvas canvas = null;
final int color = 0xffff0000;
final Paint paint = new Paint();
Rect rect = null;
if (bitmap.getHeight() > 501)
{
output = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
canvas = new Canvas(output);
rect = new Rect(0, 0, 500, 500);
}
else
{
System.out.println("output else =======");
bitmap = Bitmap.createScaledBitmap(bitmap, 500, 500, false);
output = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
canvas = new Canvas(output);
rect = new Rect(0, 0, 500, 500);
}
final RectF rectF = new RectF(rect);

paint.setAntiAlias(true);
paint.setDither(true);
paint.setFilterBitmap(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawOval(rectF, paint);

paint.setColor(Color.BLUE);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth((float) 1);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}

关于android - 以圆形显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23290018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com