如何在Java中制作圆形图像标签?

发布于 2025-02-10 16:02:10 字数 127 浏览 4 评论 0原文

如何在Java中制作圆形图像标签?

这样做。.嘿,伙计们。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

我想制作圆形图像标签,但我不能

请帮我...

How to make Circle image Label in Java?

I wanna make circle image Label But I can't do this.. Hey guys Help me..T.T

I tried make circle panel for add image icon but that didn't work.

help me please...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

请叫√我孤独 2025-02-17 16:02:10

我认为您应该更改钉子,而不是尝试修改组件的输出,而是修改输入...

“

这一切都这样做,是将圆形(基于alpha的)掩码应用于另一个图像

    BufferedImage master = ImageIO.read(new File("/Volumes/Disk02/Dropbox/MegaTokyo/thumnails/megatokyo_omnibus_1_3_cover_by_fredrin-d4oupef.jpg"));

    int diameter = Math.min(master.getWidth(), master.getHeight());
    BufferedImage mask = new BufferedImage(master.getWidth(), master.getHeight(), BufferedImage.TYPE_INT_ARGB);

    Graphics2D g2d = mask.createGraphics();
    applyQualityRenderingHints(g2d);
    g2d.fillOval(0, 0, diameter - 1, diameter - 1);
    g2d.dispose();

    BufferedImage masked = new BufferedImage(diameter, diameter, BufferedImage.TYPE_INT_ARGB);
    g2d = masked.createGraphics();
    applyQualityRenderingHints(g2d);
    int x = (diameter - master.getWidth()) / 2;
    int y = (diameter - master.getHeight()) / 2;
    g2d.drawImage(master, x, y, null);
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_IN));
    g2d.drawImage(mask, 0, 0, null);
    g2d.dispose();

    JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(masked)));

的好处,您可以得到软剪辑(哪个setClip不提供)以及不要与组件的现有剪辑形状混乱

applyqualityRenderingHints ...

public static void applyQualityRenderingHints(Graphics2D g2d) {

    g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
    g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);

}

I think you should change your tack, instead of trying to modify the output of a component, instead, modify the input...

enter image description here

So all this does, is apply a circular (alpha based) mask to another image

    BufferedImage master = ImageIO.read(new File("/Volumes/Disk02/Dropbox/MegaTokyo/thumnails/megatokyo_omnibus_1_3_cover_by_fredrin-d4oupef.jpg"));

    int diameter = Math.min(master.getWidth(), master.getHeight());
    BufferedImage mask = new BufferedImage(master.getWidth(), master.getHeight(), BufferedImage.TYPE_INT_ARGB);

    Graphics2D g2d = mask.createGraphics();
    applyQualityRenderingHints(g2d);
    g2d.fillOval(0, 0, diameter - 1, diameter - 1);
    g2d.dispose();

    BufferedImage masked = new BufferedImage(diameter, diameter, BufferedImage.TYPE_INT_ARGB);
    g2d = masked.createGraphics();
    applyQualityRenderingHints(g2d);
    int x = (diameter - master.getWidth()) / 2;
    int y = (diameter - master.getHeight()) / 2;
    g2d.drawImage(master, x, y, null);
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_IN));
    g2d.drawImage(mask, 0, 0, null);
    g2d.dispose();

    JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(masked)));

The benefit of this is you can get soft clipping (which setClip doesn't provide) as well as not messing with the existing clipping shape of a component

And applyQualityRenderingHints...

public static void applyQualityRenderingHints(Graphics2D g2d) {

    g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
    g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);

}
猫弦 2025-02-17 16:02:10

转到博客niceApplication1.blogspot.com,然后下载新的NICE应用程序1 Home Somendous,然后在提取后转到Dist文件夹并打开Java Jar nice Application 1,然后拿Jar nice_application_1_files,然后仅在某些中转换您的方法节省空间的行。

在JAR仅在您的文件位置添加以下方法和调用方法之后。

导入nice_application_1.icon;

private void addicon()抛出java.lang.nullpointerexception,ioexception {

    Icon test = new Icon("C:\\Image.jpg");

    String nice = test.icon();

    BufferedImage Appli1 = test.Application1;

    jToggleButton0.setIcon(new ImageIcon(Appli1));

}

//圆形形状图标,您可以与上述方法一起使用。

上面的示例,使用jbutton如果需要在弹出窗口中,请键入Joptionpane.showmessageDialog(null,new Jlabel(new Imageicon(Appli1)));

下载罐子后,您还可以获得更多优势。

Go to the blog NiceApplication1.BlogSpot.Com, and Download the new Nice Application 1 Home Stupendous, then after extract goes to the dist folder and open the Java Jar Nice Application 1, and take the jar Nice_Application_1_Files, and convert your method only in some lines for saving space.

After jar adds only the below method with your file location and call method.

import Nice_Application_1.Icon;

private void Addicon() throws java.lang.NullPointerException, IOException {

    Icon test = new Icon("C:\\Image.jpg");

    String nice = test.icon();

    BufferedImage Appli1 = test.Application1;

    jToggleButton0.setIcon(new ImageIcon(Appli1));

}

//Circle shape icon you can use with the above method.

Above example, with Jbutton if want in a popup so type JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(Appli1)));

After downloading the jar, you can also get more advantages.

抽个烟儿 2025-02-17 16:02:10

您可以使用区域类创建剪辑区域:

BufferedImage image = ImageIO.read(new File("..."));
Area clip = new Area( new Rectangle(0, 0, image.getWidth(), image.getHeight()) );
Area oval = new Area( new Ellipse2D.Double(0, 0, image.getWidth() - 1, image.getHeight() - 1) );
clip.subtract( oval );
Graphics g2d = image.createGraphics();
g2d.setClip( clip );
g2d.setColor( Color.BLACK );
g2d.fillRect(0, 0, image.getWidth(), image.getHeight());
JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(image)));

You can use the Area class to create a clip region:

BufferedImage image = ImageIO.read(new File("..."));
Area clip = new Area( new Rectangle(0, 0, image.getWidth(), image.getHeight()) );
Area oval = new Area( new Ellipse2D.Double(0, 0, image.getWidth() - 1, image.getHeight() - 1) );
clip.subtract( oval );
Graphics g2d = image.createGraphics();
g2d.setClip( clip );
g2d.setColor( Color.BLACK );
g2d.fillRect(0, 0, image.getWidth(), image.getHeight());
JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(image)));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文