Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8049309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:45:20+00:00 2026-06-05T06:45:20+00:00

I want to create a ring in a BufferedImage with a transparent background. I

  • 0

I want to create a “ring” in a BufferedImage with a transparent background. I can draw the circle with a transparent background like this:

BufferedImage bi = new BufferedImage(d, d, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D) bi.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(c);
g.fillOval(0, 0, d, d);

But now I want to draw a smaller transparent circle in the middle of it to make a ring (so when I draw this image over another image, the pixels around and inside the ring are not drawn). I want to use a Graphics object to do this so I can use antialiasing.

Is this possible? If it isn’t, what it the best way to tackle this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:45:21+00:00Added an answer on June 5, 2026 at 6:45 am

    Create a circular shape, then subtract another circular shape from that, set it as the clip & you might end up with something along the lines needed. To hide the rough edges of the clip, draw a 2px wide stroke of the shape.

    One ring

    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    
    public class OneRing {
    
        OneRing(BufferedImage imageBG, BufferedImage imageFG) {
            // presumes the images are identical in size BNI
            int w = imageBG.getWidth();
            int h = imageBG.getHeight();
            Ellipse2D.Double ellipse1 = new Ellipse2D.Double(
                    w/16,h/16,7*w/8,7*h/8); 
            Ellipse2D.Double ellipse2 = new Ellipse2D.Double(
                    w/4,h/4,w/2,h/2);
            Area circle = new Area(ellipse1);
            circle.subtract(new Area(ellipse2));
    
            Graphics2D g = imageBG.createGraphics();
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
            g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
            g.setClip(circle);
            g.drawImage(imageFG, 0, 0, null);
            g.setClip(null);
            Stroke s = new BasicStroke(2);
            g.setStroke(s);
            g.setColor(Color.BLACK);
            g.draw(circle);
            g.dispose();
    
            JLabel l = new JLabel(new ImageIcon(imageBG));
            JOptionPane.showMessageDialog(null, l);
        }
    
        public static void main(String[] args) throws Exception {
            URL urlFG = new URL("https://i.stack.imgur.com/OVOg3.jpg");
            URL urlBG = new URL("https://i.stack.imgur.com/lxthA.jpg");
            final BufferedImage biFG = ImageIO.read(urlFG);
            final BufferedImage biBG = ImageIO.read(urlBG);
            SwingUtilities.invokeLater(new Runnable(){
                @Override
                public void run() {
                    new OneRing(biBG, biFG);
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want create subdomains like this: domain.com/type/city An examples: domain.com/restaurants/new_york domain.com/hotels/new_york domain.com/restaurants/chicago I have
i want create something like link_to which can link to request for permission in
I want create an array in JSF EL. How can I do that? Is
I want create a new JavaScript object based on an existing JavaScript object. Till
In my app I want create thousands files in background, but when I execute
I want to create a new application (which I will sell) that uses web
I want create a pdf using iText. The method which does this is a
I want to be able to create an alarm to ring a notification to
I want create something that looks like the MSN Messenger chat forms. I am
I want create a ruby script that I can run on the command line

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.