Bufferedimage成圈形状 [英] Bufferedimage into circle shape

查看:194
本文介绍了Bufferedimage成圈形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个来自字节数组的缓冲图像。我如何将图像变成一个圆圈?作物?我不想要一个圆圈,我想让原始图像变成圆形并显示出来。

  def bufferedImage = imgSvc.convertByteArrayToBufferedImage( crop.image)


解决方案

使用下面的代码:

  int width = bufferedImage.getWidth(); 
BufferedImage circleBuffer = new BufferedImage(width,width,BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = circleBuffer.createGraphics();
g2.setClip(new Ellipse2D.Float(0,0,width,width));
g2.drawImage(bufferedImage,0,0,width,width,null);

你可以在 circleBuffer

I have a buffered image from byte array. How do I make the image into a circle? Crop? I don't want a circle, I want the orginal image to become circle shape and display

 def bufferedImage = imgSvc.convertByteArrayToBufferedImage(crop.image)

解决方案

If bufferedImage is squared, then with this code :

int width = bufferedImage.getWidth();
BufferedImage circleBuffer = new BufferedImage(width, width, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = circleBuffer.createGraphics();
g2.setClip(new Ellipse2D.Float(0, 0, width, width));
g2.drawImage(bufferedImage, 0, 0, width, width, null);

you get a circular cropped image in circleBuffer

这篇关于Bufferedimage成圈形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆