Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distorted circle in android using canvas

Paint p = new Paint();
    p.setAntiAlias(true);
    p.setColor(Color.DKGRAY);
    int y=getWindowManager().getDefaultDisplay().getWidth();
    Config conf = Bitmap.Config.RGB_565;
    Bitmap bmp =Bitmap.createBitmap(y,y,conf);
    Canvas c = new Canvas(bmp);
    c.drawCircle(y/2 ,y/2, y/3, p);
    iv.setBackgroundDrawable(new BitmapDrawable(bmp));

By this code i do get circle ,which is looking as:-

Now the problem is that it doesnt look like a true circle ,and it looks like an oval shape..

So what should i do ??

Thanks in advance,....

like image 466
aagam94 Avatar asked Dec 05 '25 10:12

aagam94


1 Answers

iv.setBackgroundDrawable(new BitmapDrawable(bmp));

use setImageBitmap(), instead of setBackgroundDrawable(), and setScaleType() to FIT_CENTER

like image 199
Blackbelt Avatar answered Dec 08 '25 00:12

Blackbelt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!