I have created an android application in that I want to display image in image view from in round shape.
My code is:
private class LoadImage extends AsyncTask<String, Void, String>
{
Bitmap image=null;
@Override
protected String doInBackground(String... params)
{
try
{
URL url = new URL(imgUrl);
image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
image=Global.getRoundedShape(image);
}
catch (Exception e)
{
e.printStackTrace();
}
return "Executed";
}
@Override
protected void onPostExecute(String code)
{
try
{
profilepic.setImageBitmap(image);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
public static Bitmap getRoundedShape(Bitmap scaleBitmapImage)
{
int targetWidth = 168;
int targetHeight = 166;
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;
}
I use this code, but it takes much load for load Image.
So, is there any option to make it fast ?