`
wang_peng1
  • 浏览: 3960602 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

从图片中截取圆形图片

 
阅读更多
int targetWidth = 100;
    int targetHeight = 100;
    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 = BitmapFactory.decodeResource(
        getResources(),
        R.drawable.my_image);
    canvas.drawBitmap(
        sourceBitmap,
        new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()),
        new Rect(0, 0, targetWidth, targetHeight),
        null);
    ImageView imageView = (ImageView)findViewById(R.id.my_image_view);
    imageView.setImageBitmap(targetBitmap);

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics