java - How to maintain qualtiy of the image downloaded from url to imageview and crop them to a circle? -


i using following code of 'android universal image loader' library, quality of image poor , many skipped frames in logcat, here code, please , how can improve it?

private class downloadimagetask extends asynctask<string, void,         bitmap> {     imageview bmimage;      public downloadimagetask(imageview bmimage) {         this.bmimage = bmimage;     }      protected bitmap doinbackground(string... urls) {         string urldisplay = urls[0];         //  bitmap micon11 = null;         imageloader imageloader = imageloader.getinstance();         bitmap bitmap = imageloader.loadimagesync(urldisplay);           bitmap circlebitmap = bitmap.createbitmap(bitmap.getwidth(), bitmap.getheight(),                 bitmap.config.argb_8888);          bitmapshader shader = new bitmapshader(bitmap, tilemode.clamp, tilemode.clamp);         paint paint = new paint();         paint.setshader(shader);          canvas c = new canvas(circlebitmap);         c.drawcircle(bitmap.getwidth() / 2, bitmap.getheight() / 2, bitmap.getwidth() / 2, paint);          //img1.setimagebitmap(circlebitmap);         //bmimage.setimagebitmap(circlebitmap);         return circlebitmap;      }      protected void onpostexecute(bitmap result) {           bmimage.setimagebitmap(result);     } } 

import android.graphics.bitmap; import android.graphics.bitmapshader; import android.graphics.canvas; import android.graphics.paint;  import com.squareup.picasso.transformation;   public class circletransform implements transformation {     @override     public bitmap transform(bitmap source) {         int size = math.min(source.getwidth(), source.getheight());          int x = (source.getwidth() - size) / 2;         int y = (source.getheight() - size) / 2;          bitmap squaredbitmap = bitmap.createbitmap(source, x, y, size, size);         if (squaredbitmap != source) {             source.recycle();         }          bitmap bitmap = bitmap.createbitmap(size, size, source.getconfig());          canvas canvas = new canvas(bitmap);         paint paint = new paint();         bitmapshader shader = new bitmapshader(squaredbitmap, bitmapshader.tilemode.clamp, bitmapshader.tilemode.clamp);         paint.setshader(shader);         paint.setantialias(true);          float r = size/2f;         canvas.drawcircle(r, r, r, paint);          squaredbitmap.recycle();         return bitmap;     }      @override     public string key() {         return "circle";     } } 

try this:

picasso.with(context).load("url").transform(new circletransform()).into(target); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -