简体   繁体   English

如何在java中将图像裁剪成圆形?

[英]How to crop an image into circle in java?

I am working on a small Inventory System for my university project, I am planning that admin should be able to change the system logo.我正在为我的大学项目开发​​一个小型Inventory System ,我计划管理员应该能够更改系统徽标。

The problem is when admin changes the photo, it will be displayed as original size and shape and the whole look get ugly so here is my question.问题是当管理员更改照片时,它将显示为原始大小和形状,整个外观变得丑陋,所以这是我的问题。

How can I crop the image into a circle and 250 x 250 pixel?如何将图像裁剪成circle250 x 250像素?

PS When I first asked this question, I just started learning Java and my English language was not good; PS 刚开始问这个问题的时候,刚开始学Java,英文不好; so here I am 4 and a half years letter editing my own question completely.所以在这里我用了 4 年半的时间来完全编辑我自己的问题。

A label is transparent by default.默认情况下,标签是透明的。

So either you have non-transparent pixels in your image or the frame itself is not transparent so you see the frame background.因此,要么您的图像中有非透明像素,要么框架本身不透明,因此您可以看到框架背景。

Read the section from the Swing tutorial on How to Create Translucent and Shaped Windows for more information on transparent frames.有关透明框架的更多信息,请阅读 Swing 教程中有关如何创建半透明和异形窗口的部分。

Basiclly you need to use a non decorated frame and then use:基本上你需要使用一个非装饰框架,然后使用:

frame.setOpacity(0.0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM