0

Trying to load a image from a website and crop the center of that particular image into a circle. I currently am trying to us the below code. There are two things wrong with the code... One is I cannot use net functions in my main method. And two I am cropping it correctly?

private Drawable getAvatar(String link) {
    RoundedBitmapDrawable drw = null;
    try {
        URL url = new URL(link);
        Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
        drw = RoundedBitmapDrawableFactory.create(Resources.getSystem(), bmp);
        drw.setCornerRadius(Math.max(bmp.getWidth(), bmp.getHeight()) / 2.0f);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    return drw;
} 

I think my options are to either make a new class that is a thread and load all images there... I need these images to be updated into another activity.

AsyncTask is causing skipping in frames I need a real thread but still need to update UI

Convexity
  • 1
  • 2

1 Answers1

0

Try to use async task to do processes in background which you are not supposed to be doing on main thread.

For cropping an image you can do this. This example crops any image in circle.

Community
  • 1
  • 1
overlord
  • 1,059
  • 1
  • 14
  • 21