Draw a line on ImageView set by Picasso

故事扮演 提交于 2019-12-02 07:25:32

just follow the steps below:

  1. Write your own class extends the class Transformation like below:

     class DrawLineTransformation implements Transformation {
    
      @Override
      public String key() {
        // TODO Auto-generated method stub
        return "drawline";
      }
    
      @Override
      public Bitmap transform(Bitmap bitmap) {
        // TODO Auto-generated method stub
        synchronized (DrawLineTransformation.class) {
          if(bitmap == null) {
            return null;
          }
          Bitmap resultBitmap = bitmap.copy(bitmap.getConfig(), true);
          Canvas canvas = new Canvas(resultBitmap);
          Paint paint = new Paint();
          paint.setColor(Color.BLUE);
          paint.setStrokeWidth(10);
          canvas.drawLine(0, resultBitmap.getHeight()/2, resultBitmap.getWidth(), resultBitmap.getHeight()/2, paint);
          bitmap.recycle();
          return resultBitmap;
        }
      }
    }
    

    2、Add the Transformation to RequestCreator created with Picasso.load() function like below:

    Picasso picasso = Picasso.with(getApplicationContext());
    DrawLineTransformation myTransformation = new DrawLineTransformation();
    picasso.load("http://www.baidu.com/img/bdlogo.png").transform(myTransformation).into(imageview);
    

That's all steps you need to do , just enjoy!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!