Anti-aliased image clipping

I could really use some help with this.. I am completely stuck!
I want to take a square BufferedImage (created from a jpeg)
and clip it with an inscribed circle, such that only a circular image
cutout remains (and the exterior of the circle is transparent).
However, I need to do this with anti-aliasing so that the edge of the
circle is smooth.
I have tried the following two methods, but neither one produces
the correct result:
//simply returns the original image
private static BufferedImage cutoutCircle(BufferedImage img, int w, int h) {
Graphics2D g2d = img.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Shape circle = new java.awt.geom.Ellipse2D.Double(0,0,w,h);
g2d.setClip(circle);
return img;
//cuts out circle but not anti-aliased
private static BufferedImage cutoutCircle(BufferedImage orig, int w, int h) {
BufferedImage bimg = new BufferedImage(w, h,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bimg.createGraphics(); //this is blank (transparent)
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Shape circle = new java.awt.geom.Ellipse2D.Double(0,0,w,h);
g2d.setClip(circle);
g2d.drawImage(orig, 0, 0, null);
return bimg;
}

At least try to run this code, and then maybe you'll start trying to think about what I said.
import javax.imageio.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.*;
import java.awt.geom.*;
public class UseYourBrain extends JPanel implements MouseMotionListener, MouseListener {
     private BufferedImage image = null;
     private double radius = 100;
     private Area area = null;
     private Color antialiasColor = Color.black;
     public UseYourBrain(BufferedImage img) {
          super();
          image = img;
          addMouseListener(this);
          addMouseMotionListener(this);
     public void mousePressed(MouseEvent evt) {
          setArea(evt.getX(), evt.getY());
          repaint();
     public void mouseReleased(MouseEvent evt) {}
     public void mouseClicked(MouseEvent evt) {}
     public void mouseEntered(MouseEvent evt) {}
     public void mouseExited(MouseEvent evt) {}
     public void mouseDragged(MouseEvent evt) {
          setArea(evt.getX(), evt.getY());
          repaint();
     public void mouseMoved(MouseEvent evt) {}
     private void setArea(int x, int y) {
          int w = image.getWidth();
          int h = image.getHeight();
          area = new Area(new Rectangle(0, 0, w, h));
          area.subtract(new Area(new Ellipse2D.Double(x, y, radius, radius)));
     public void paint(Graphics _g) {
          super.paint(_g);
          Graphics2D g = (Graphics2D) _g;
          g.drawImage(image, 0, 0, this);
          if (area != null) {
               g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
               g.setColor(antialiasColor);
               g.fill(area);
     public static void main(String[] args) throws Throwable {
          if (args.length == 0) {
               System.out.println("Usage: UseYourBrain <filename>");
               System.exit(0);
          JFrame f = new JFrame();
          BufferedImage img = ImageIO.read(new java.io.File(args[0]));
          JPanel p = new UseYourBrain(img);
          f.setContentPane(p);
          f.setSize(500, 500);
          f.show();
          f.addWindowListener(new WindowAdapter() {
               public void windowClosing(WindowEvent evt) {
                    System.exit(0);
}

Similar Messages

  • The images in Photoshop or InDesign improperly anti-aliased, looking fuzzy

    I've bought Late 2013 Retina Macbook Pro with Mac OS Mavericks, and am having trouble with anti-aliasing.
    In short, the images/documents open in Photoshop or InDesign are improperly anti-aliased and look fuzzy.
    I can understand why the menu bars and stuff should appear fuzzy and blurry as a result of auto anti-aliasing; otherwise they might appear too small for eyes to see since the resolution is super high.
    But why should the machine want to blow up the images or documents inside the application and apply anti-aliasing to make them look so fuzzy?
    It would be grateful if there's a way to stop my computer doing the anti-aliasing all the stuff on screen.

    No, not that I know of - you do need to make certain that you're using the very latest versions of both apps, though.
    Clinton

  • Resized images are not anti-aliased

    I'm creating an app with html + js + css + air, and I'm doing
    something like this:
    <img src="
    http://somedomain.com/image.jpg"
    />
    I find that if I set the image height/width in css that when
    the image loads it displays in very poor quality, mainly it looks
    like it's not anti-aliased. The images look fine when I don't set a
    height or width, so the images look fine by themselves, and when
    rendered at their original size. It's only when I try to resize it
    that it looks bad.
    Any help is greatly appreciated - many thanks.

    Thanks for the suggestion zorglub76. Perhaps I could find a
    solution resizing the image in actionscript, but then I'm stuck
    with another problem, which is how to take an image I've
    manipulated in AS3 and render it in the html img tag? I'm
    dynamically pulling images from amazon, so I can't resize them
    ahead of time.
    As far as the css goes, I don't believe that's the problem.
    When I take the same html + css and render it in chrome, firefox,
    or safari the smaller image looks great. It's only a problem in
    adobe air, and I believe it has to do with it not being
    anti-aliased.

  • Anti-aliased text when exporting PDF to image

    I need to be able to batch-convert multi-page PDFs to individual bitmap images (one image for each page) with anti-aliased text.
    Photoshop works this way if you open a single PDF, allowing you to select one or more pages to rasterize as separate images, but not when batch processing (specifically, if you use the Image Processor script on a folder of images and PDFs, it will rasterize the PDFs automatically, but it will only do so with the first page of each PDF.)
    Acrobat, on the other hand, automatically creates an image for each page when exporting, and can do this in a batch sequence, but the text is not anti-aliased, making the image look like a screenshot from 1997. No matter how high an image resolution you select, the text is still jagged when you zoom in.
    So, is there a setting I'm missing that will allow the text to be anti-aliased when using Acrobat to export PDF to an image? I am using Acrobat 8, not 9, so something might have changed in the newest version.

    Not sure about Acrobat Pro 8, but in Acrobat Pro 9 (not Extended) you can Export>Image>Multiple Choice: JPEG, JPEG2000, PNG, TIFF.  I used JPEG and under the options in the export dialog box, leave the filename as is to coincide with the PDF filename and then choose Maximum Resolution under File Settings: Grayscale (JPEG, Quality:Maximum); Color (JPEG, Quality:Maximum) . . . skip down to Conversion Colorspace: Determine Automatically and Resolution choose 600pixels/inch for a letter size document.  This will result in a file size of 1.3MB per JPEG image if there is not a lot of information on the page.  I chose a simple header, footer with page numbering, and 5 lines of Lorem Ipsum text.  600dpi is overkill, you can go for 300dpi and still result in a decent image that will be able to be printed on a laser photocopier that is connected to a production computer.  Obviously if you are printing to a laser printer or a high quality inkjet 300dpi will suffice as well for a letter sized document.  But I have been told that 300dpi is not a standard rule of thumb and you must obtain specs from your printer since he/she can calculate by very strict rules the dpi you need for your content.  It depends on whether you have background images such as watermarks and also if your text body contains line-art.

  • I am using the pen tool to clipp an image. Sometimes when I apply the mask WITH NO FEATHER it still appears to be feathered? Does this have to do with Anti-aliasing

    I am using the pen tool to clipp an image. Sometimes when I apply the mask WITH NO FEATHER it still appears to be feathered? Does this have to do with Anti-aliasing?

  • Reducing image sizes - not anti-aliasing

    Hi guys,
    I've had a search around and haven't found much on this specifically (it's also a difficult thing to search for) so I hope someone here could maybe shed some light.
    I'm fairly new to using Flash but well versed in other adobe software.
    I have this problem:
    I'm tweening a symbol so that it reduces in size. It was a png image. It goes from being big to small. When it's small it becomes less anti-aliased (clear jagged edge, more visible and directly proportional to how much it has been reduced)
    This is something unrelated to actual tweening - it's just become obvious in this situation. It also happens when simply resizing using transform tools.
    Here are some screen shots:
    Thoughts?
    Sam

    Hi Ned,
    Cheers for the answer but it's actually made no difference. It acts the same.
    In any case, this time I don't have the time to faff about so I'll just live trace it and use a vector.
    Thanks anyway, I'll mark this as answered; someone else might find it helpful.

  • CS5 Export to web images not anti-aliased

    Never saw this in CS3. Don't see a preference in export to web to turn on anti alias. Any export to web out of AI has bitmapped edges.
    I have to export to Photoshop first.
    What am I missing?

    sonofmrsnak wrote:
    I have to export to Photoshop first.
    Are you saying you have a need to use Photoshop or that, because of the lack of anti-aliasing, you are forced to go through Photoshop? If the former, then just open the Illustrator file in Photoshop. If the latter, then look at his in Illustrator’s Save for Web window…
    Note: This is in Illustrator CS5. I think it’s just an Antialias check box in earlier versions.

  • Photoshop CS4 Brushes not Anti Aliasing properly

    I've just set up CS4 and my brushes are not anti aliasing properly. There are no soft edges on any of them. I'm able to get a pressure sensitive opacity change on the stroke but the edges are all pixelated.
    Here is an image (this is a soft brush. notice none of the feathering/anti aliasing is there):
    http://craji.com/images/adobeproblem.jpg
    I've updated the newest gpu drivers for my Nvidia 8800 GTS.
    I'm running XP SP3 with dual monitors. An Apple 30" and a Cintiq 21"
    I've tried placing the main photoshop window on both monitors (one at a time) to test if that was causing it and i've had no luck.
    All of the options in my GPU Enabled are currently unchecked (since they were giving me lag issues on my brush stroke when they were checked).
    Any help (even linking me to something similar in this forum) is greatly appreciated.
    Cheers-

    Definitely not file dependent. I'll open a photo in sRGB 8bit, or create a new document with any settings from cmyk/rgb/bw 8/16 etc.
    I'm wondering if it has something to do with my Nvidia Display Property utility. I use it to gamma up my secondary monitor (cintiq). Although disabling that utility didn't resolve it..
    I'll try uninstalling and reinstalling tonight if no one is having similar problems. Maybe that will fix it.

  • CS5 bug rendering anti-aliased text in 'Save for web'

    Seems like there's a bit of a bug when using 'Save for web and devices' with thin weights of type in CS5 for Mac. Although thin type looks fine while working in Illustrator, as soon as you enter the 'Save for web' dialogue, it gets badly mangled. Looks like this issue has been present at least since CS4. It does not happen in Photoshop. It looks particularly bad for light text on a dark background.
    Some people may say "sure, Illustrator is not really meant for intensive bitmap work". However, with features like 'pixel preview' and 'snap to pixel', Illustrator has (generally) become a very viable tool for web design, and personally I much prefer it to Photoshop. It is also clear that Adobe intends it to be usable in this manner. So the anti-aliasing render bug is definitely a problem. Just surprised they didn't address it when CS5 was born.
    I put up some example images on http://www.thesheep.co.uk/2011/06/24/illustrator-save-for-web-anti-aliasing-problems/ to illustrate the problem.
    Does anyone have any clever work-arounds for this? It's a bit annoying to have to move stuff over to PS before exporting, but maybe that's what I have to do. Hopefully Adobe will address this soon.

    Hi,
    I am experiencing this same problem of pixelated gifs when I use the "save for web" dialog from Illustrator, but this solution has not worked for me. I have tried the trick of using type-optimized anti-aliasing, but it doesn't change the output at all. I've done this from within the "Image size" tab as well as through Effect>Rasterize>Options)Anti-aliasing: Type Optimized. My image is a logo made entirely from text, although for some of it I used "outline path", so I'm not sure if it still qualifies as text...I'm a newbie at this stuff, so the technical details are still quite opaque to me.
    Does anyone know of a solution to this that does not require me to add Photoshop to my workflow?
    I'm using Illustrator in CS5, version 15.0.2.
    Thanks in advance
    Jonathan

  • Possible bug in Illustrator CS4 text anti-aliasing in Save for Web and Devices

    Hello all,
    This could be a bug... if so, I'd be happy to add it to Wade's bug list a few messages down the stream.
    Here's what's happening: when I create small text using a very thin font (in this case, Helvetica Neue Light), the Pixel Preview gives a noticeably different anti-aliasing solution to the actual output from Save for Web & Devices. I'm attaching an original .AI file as well as a screenshots of what I'm getting in both situations.
    I'd really prefer the Save for Web and Devices output to look exactly like the Pixel Preview. The font looks great in Illustrator but loses a lot of its punch when I Save for Web.
    ---Peter

    In the Svae for Web and Device  under the image tab where it says art Optimize that is a drop down menu select Type Optimize as such
    htis is what it lloks like in AI and a browser when you choose Type Optimize
    This the difference between Art Optimized and Type Optimize
    That is what is happening to you you are selcting Art Optimize and that is the reason when you choose art optimize aqnd you rraster the image it looks right to you.

  • Preview - anti aliasing and text in scanned pdf

    hello all,
    i have an issue with preview not anti aliasing text in pdf files.  to elaborate, take a pdf with text which is selectable and it appears jagged, not anti aliased as in pdfs with text which is treated as an image, i.e. not selectable.
    also, sometimes, when scrolling through pages in full screen, the following page has the text anti-aliased as the scroll animation is taking place, i.e. while the previous page is being moved away through the gesture, but once the previous page has disappeared and the new page 'settled in' the smoothing is gone.
    smooth text and line art is checked, as is lcd smoothing in general preferences.
    any suggestion are much appreciated.
    s.

    Hi 1ndivisible,
    Hmm, that's odd. My type is looking pretty decent out of Illustrator. Can you try a different font or the same font in a new sequence?
    Thanks,
    Kevin

  • REPORT: Bug in OS X's anti-aliasing w/ rotated screen

    This is a fairly substantial bug. This may not be the ideal place to post it, but could someone tell me where to submit this so Apple will take notice?
    A friend and I both have Mac Pros w/ ATI X1900 displays. This video card supports screen rotation in the OS X Displays control panel. So he went out and grabbed a rotating 1600x1200 Samsung (4:3) display to set next to his 30" Apple Cinema Display (both 1600 pixels tall, when the Samsung is in portrait orientation - a good match).
    Have a look at the setup:
    http://www.hubbuddy.com/downloads/dual/DSCN0914.jpg
    He has his 'Font smoothing style' in the Appearances prefs pane set to "Medium - best for flat panel." This setting uses subpixeling, providing up to 3x the horizontal resolution of the screen's native pixel width. (More about sub-pixeling here: http://www.grc.com/cleartype.htm )
    Sub-pixeling depends upon the orientation of the RGB elements of each sub-pixel cluster that makes up a pixel. When a screen is rotated 90-degrees, the RGB "stripes" run horizontal, not vertical. As can be seen from the below images, where the first image (ONE) shows the rotated Samsung and the second image (TWO) shows the standard orientation Apple Cinema 30", OS X's sub-pixeling does NOT take into account the new orientation of the sub-pixel clusters, resulting in a rather bold and crude rendering of text on the rotated first (ONE) image:
    http://www.hubbuddy.com/downloads/dual/one.jpg
    http://www.hubbuddy.com/downloads/dual/two.jpg
    Apple needs to correct this so that people don't have to abandon sub-pixeling and use 'Standard' (greyscale) anti-aliasing. Microsoft takes sub-pixel cluster orientation into account with Windows Mobile (CE) on the Pocket PC's. Surely Apple can get this working with rotated screens under OS X.
    Thanks. Where do I submit this?
    bp

    Digg this story...
    http://www.digg.com/apple/OSX_supports_screen_rotation_but_its_rotated_anti_aliasing_isbroken
    ...to get the word out. (Just trying to get this addressed.)
    blakespot

  • What does the anti-aliasing feature of the graph do?

    I see when I right click a graph anti-aliasing is an option. What does this feature on the graph allow you to do?

    > I see when I right click a graph anti-aliasing is an option. What does
    > this feature on the graph allow you to do?
    As Dennis points out, it smooths the image. Specifically, computer
    graphics on a raster device have stair-steps or jaggies. This occurs
    because a sloping line is being approximated by setting pixels in a grid
    to either the foreground or background color. For this example, lets
    assume the BG is black and FG is white. At 45 deg and certain other
    nice angles, the lines look relatively smooth, like the diagonals on a
    chess board, but at other angles, they are heavily aliased or jaggy.
    Anti-aliasing sets the color of the pixels to black, white, or shades of
    gray depending on the amount of the pixel that intersects the
    mathematical d
    efinition of the line. This extra math slows things down,
    and the fact that the anti-aliasing is done not by windows, by by an
    OpenGL driver in its own memory buffer slows it down further. For
    slowly changing plots, they look quite nice. This doesn't make sense
    for dense data or quickly changing data.
    Greg McKaskle

  • Font Anti-Aliasing Issues in HTML/Ajax based Air Applications

    It seems that the font-renderer in HTML/Ajax based Air Applications is using some kind of sub-pixel font renderer that is overriding and vastly inferior to the standard Windows ClearType, or any Apple based option as well.  This problem is particularly noticable with light text on a dark background, and made worse the smaller the text is.  I've put together an example image explaining exactly what I mean at: http://regator.com/fontRendering.png   (it's a large image 1126 x 1500 px)
    My example shows two fonts at four different sizes rendered in an HTML Air App vs the default Windows Cleartype, as well as using Safari to show the Font style anti-aliasing.  In all cases the HTML Air App rendering is far more difficult to read, and in many cases severely distorts the color of the text in a way that other subpixel algorithms do not.  As far as I can find after literally hours of googling and searching there's no way to override this in HTML based applications.  Is there any solution to this, or a planned fix for the renderer?  Other than this rendering issue, the HTML interface for creating Air apps is absolutely brilliant, this is just making my finished product look significantly less polished than it otherwise would if the text were more readable.
    Thanks.

    Dear caturner81, dear Adobe,
    is there a solution to this problem? I'd really love to fix the aliasing thing in Air/HTML!

  • [CS5][Save for Web][Anti-aliasing] Fine lines in exported PSD with adjustment layers

    Hello,
    You can reproduce the bug this way:
    - link a PSD with a adjustment (Levels, Brightness/Contrast) layer in your AI file
    - Save for Web, with AA for Art (not text) selected
    In the exported image there will be artefacts, white lines usually.
    Flattening the PSD or deleting the adjustment layers will solve the problem and anti-aliasing will be applied correctly.
    I used CMYK/RGB settings, FOGRA39/Adobe RGB 1998 for all the files involved.

    Hi,
    I am experiencing this same problem of pixelated gifs when I use the "save for web" dialog from Illustrator, but this solution has not worked for me. I have tried the trick of using type-optimized anti-aliasing, but it doesn't change the output at all. I've done this from within the "Image size" tab as well as through Effect>Rasterize>Options)Anti-aliasing: Type Optimized. My image is a logo made entirely from text, although for some of it I used "outline path", so I'm not sure if it still qualifies as text...I'm a newbie at this stuff, so the technical details are still quite opaque to me.
    Does anyone know of a solution to this that does not require me to add Photoshop to my workflow?
    I'm using Illustrator in CS5, version 15.0.2.
    Thanks in advance
    Jonathan

Maybe you are looking for

  • Error in retraction program

    when trying to retract information from BIW to Funds Management, what does the following error mean: Source type \CLASS=CL_ABAP_ELEMDESCR is not compatible, for the purposes of assignment, with target type \CLASS=CL_ABAP_STRUCTDESCR Message no. RS_EX

  • IPad keeps freezing and flashing and jumping to other apps

    My Iliad mini is one year old. About 3 months ago it started acting up. It flashes on and off within an app. Sometimes in a game it makes moves for me. I tried updating but I keep getting an error because the update never completes.

  • XI Integration Builder API and Javadocs

    Hi I have been asked to produce a standalone app that will change the XSL files in a software component on XI. This requires the component to be made writeable, edited, and then its change list be submitted. I have tried to find an API that offers th

  • SCSI Disc Read-Only

    hi i have Arch linux installed on my SCSI disc (Seagate Cheetah 18GB) my controler is Adaptec AHA-2940U/UW / AHA-39xx / AIC-7895 (rev 04) working on kernel 2.6.15-ARCH (from 0.7.1 installation CD) with default initrd .... sometimes i get error like (

  • Accordion Widget Starting Closed

    I am trying to use the accordion widget on the following page: http://jalc.org/jazzED/s_eac.html I am having a problem getting the page to load with the widget panels closed except the first one. I have added the following code to just below the DIV