2013-09-30 34 views
-1

在我的应用程序中,我想要图像round.I使用以下方法来圆形图像。Imageview带圆角的图像不起作用

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) { 


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; 
} 

,我使用下面的XML:

<ImageView 
    android:layout_centerInParent="true" 
    android:layout_height="150dp" 
    android:layout_width="150dp" 
    android:src="@drawable/default_profilepic" 
    android:id="@+id/image" 
    android:layout_alignParentLeft="true" 
    android:layout_marginLeft="13dp" 
    android:layout_marginTop="0dp" 
    android:scaleType="fitXY" /> 

,我使用ImageLoader的类,因为我在我的课让图像url.So我用follwing代码:

imgLoader.DisplayImage(strFBProfilePic, imgProfilePic); 

而在我的图像加载器类中,我在displayimage方法中使用波纹管代码:

dispImage=ImageHelper.getRoundedCornerBitmap(bitmap, 150); 
imageView.setImageBitmap(dispImage); 

,最后我得到了像以下的输出:

enter image description here

所以,请建议我在我的code.Tanks没有错在事先

回答

1

我猜getRoundedCornerBitmap方法的第二个参数是角落的半径。先给一个较小的值,如

dispImage = ImageHelper.getRoundedCornerBitmap(bitmap, 10); 
+0

它不工作,如果我用10我得到了矩形贮image.but我想四舍五入的图像 – rams

+0

好了,也许10是不够的。试着调整参数,直到你得到你期望的结果。 – ssantos

+0

是的,我试过50,100,150和200 also.but但我得到相同的输出只有 – rams