sha*_*esh 28 android imageview
我想做那样的事.

这是一个列表视图行,其中包含名称和用户图像.
我做了一些搜索并完成了图像循环,但不是完美的解决方案.任何帮助都会帮助我.
我的代码添加到Image Loader类
public Bitmap processBitmap(Bitmap bitmap) {
int pixels = 0;
if (mRound == 0)
pixels = 120;
else
pixels = mRound;
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());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
Piy*_*ush 47
你也可以使用这个功能...它的工作对我来说..
public Bitmap getRoundedShape(Bitmap scaleBitmapImage) {
int targetWidth = 50;
int targetHeight = 50;
Bitmap targetBitmap = Bitmap.createBitmap(targetWidth,
targetHeight,Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(targetBitmap);
Path path = new Path();
path.addCircle(((float) targetWidth - 1) / 2,
((float) targetHeight - 1) / 2,
(Math.min(((float) targetWidth),
((float) targetHeight)) / 2),
Path.Direction.CCW);
canvas.clipPath(path);
Bitmap sourceBitmap = scaleBitmapImage;
canvas.drawBitmap(sourceBitmap,
new Rect(0, 0, sourceBitmap.getWidth(),
sourceBitmap.getHeight()),
new Rect(0, 0, targetWidth, targetHeight), null);
return targetBitmap;
}
Run Code Online (Sandbox Code Playgroud)
And*_*Res 10
这可能不会回答你的问题,但是,作为一种替代方案,你可以通过在一个FrameLayout例子中设置2个ImageView来模仿这种效果:一个在底部 - 这将是图片,一个在顶部 - 这将是一个灰色正方形,中间有一个圆圈,圆圈的"身体"是透明的.
这样您就不必进行任何位图处理.但是,选择一个更适合您需求的产品.
这要归功于答复.
Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Paint paint = new Paint();
paint.setStrokeWidth(5);
Canvas c = new Canvas(circleBitmap);
//This draw a circle of Gerycolor which will be the border of image.
c.drawCircle(bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getWidth()/2, paint);
BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint.setAntiAlias(true);
paint.setShader(shader);
// This will draw the image.
c.drawCircle(bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getWidth()/2-2, paint);
Run Code Online (Sandbox Code Playgroud)

圆角图像使用imageLoader github.com/nostra13/Android-Universal-Image-Loader创建选项;
DisplayImageOptions options = new DisplayImageOptions.Builder()
// this will make circle, pass the width of image
.displayer(new RoundedBitmapDisplayer(getResources().getDimensionPixelSize(R.dimen.image_dimen_??menu)))
.cacheOnDisc(true)
.build();
imageLoader.displayImage(url_for_image,ImageView,options);
Run Code Online (Sandbox Code Playgroud)
或者U可以从squre使用Picasso Library.
Picasso.with(mContext).load(URL+b.image)
.placeholder(R.drawable.profile)
.error(R.drawable.profile)
.transform(new RoundedTransformation(50, 4))
.resizeDimen(R.dimen.list_detail_image_size, R.dimen.list_detail_image_size)
.centerCrop()
.into(v.im_user);
Run Code Online (Sandbox Code Playgroud)
你可以在这里下载RoundedTrasformation 文件
重要提示:我在使用UIL时发现了一个问题.如果你没有在ImageView中放置xml属性android:contentDescription ="TODO".然后UIL显示简单的图像.希望大家都明白
| 归档时间: |
|
| 查看次数: |
63398 次 |
| 最近记录: |