Drawing and filling with color in an image?

How to draw an eclipse or a shape in the image (picture)?
I want to whiten (convert to white color) all pixel elements outside the shape, and the pixel elements inside the shape remain the shape.
Pliz give some hints.
Regards,
Chevas

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.*;
import javax.imageio.ImageIO;
import javax.swing.*;
public class Mask extends JPanel
    BufferedImage image;
    public Mask()
        loadImage();
    protected void paintComponent(Graphics g)
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        int w = getWidth();
        int h = getHeight();
        int imageWidth = image.getWidth();
        int imageHeight = image.getHeight();
        int x = (w - imageWidth)/2;
        int y = (h - imageHeight)/2;
        g2.drawImage(image, x, y, this);
        Area mask = new Area(new Rectangle(0,0,w,h));
        Ellipse2D e = new Ellipse2D.Double(w/6, h/8, w*2/3, h*3/4);
        mask.subtract(new Area(e));
        g2.setPaint(Color.white);
        g2.fill(mask);
    private void loadImage()
        String fileName = "images/owls.jpg";
        try
            URL url = getClass().getResource(fileName);
            image = ImageIO.read(url);
        catch(MalformedURLException mue)
            System.err.println("url: " + mue.getMessage());
        catch(IOException ioe)
            System.err.println("read: " + ioe.getMessage());
    private void saveAsImage()
        int w = getWidth();  // or you could use the width and height
        int h = getHeight(); // of the mask to clip the image...
        BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        paint(g2);  // this component paints itself into the new image
        g2.dispose();
        try
            ImageIO.write(image, "jpg", new File("mask.jpg"));
        catch(IOException ioe)
            System.err.println("write: " + ioe.getMessage());
    private JPanel getUIPanel()
        JButton save = new JButton("save");
        save.addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent e)
                saveAsImage();
        JPanel panel = new JPanel();
        panel.add(save);
        return panel;
    public static void main(String[] args)
        Mask mask = new Mask();
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(mask.getUIPanel(), "North");
        f.getContentPane().add(mask);
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
}

Similar Messages

  • How to draw and fill gradient color ?

    i'm trying to fill the gradient color for the customize shapes in my application please tell how to approach for this problem.

    I sloved by cliping it by clipping gradient color with respec to path

  • Brushes have pixelated edge: when filled with color there's a white line at the border

    Hello,
    I'm trying to make geometric shapes that are black outlines filled with color. I'm drawing the shapes with the pen tool. When I fill them using the bucket tool, there's a pixellated white line separating the black outline and the color infill. How to do make the color fill directly to the black outline?
    Thanks for your help,
    DJ
    CS4
    OS 10.5.8

    In addition to Chris's post wanted to advise you that stroke effects in Phothsop have rounded edges in Phothoshop. You will notice this on thin strokes (eg: 1 pxl).
    Set the stroke to go on inside for squared edges, not center or outside. Adobe has been aware of this since CS, but has not been find a solution for Photoshop to handle this.

  • Crop and fill with image

    Hello
    I intend to use lasso for free style cropping an image, but I want to the fill in that cropped section with another image. I intend to , say crop a dress floral pattern on a sleeve, and fill it with another floral pattern of my choice.
    Thanks

    Hi there,
    Here's a quick tutorial for working with masks to replace patterns and textures in an image.
    1) Here's my starting image, and I want to replace the fabric on the pocket of this shirt.
    2) Bring in the pattern you want to incorporate into your original image by copy and pasting or by going to File > Place.
    3) With the pattern layer selected, option + click on the icon marked below to create a mask over the layer. The image will seem to disappear, but this is only because the mask is solid black— black in the mask indicates hidden areas, white areas are where the image will be revealed.
    4) Use the lasso tool to select the area in which you want the pattern to appear.
    5) Being sure the mask is selected in the layers panel, use the paint bucket to fill in the selection area with white. The pattern will appear.
    My next steps would then be to paint on the mask with black to reveal the stitched areas and the button on the pocket. Alternatively, as Silkrooster said, you can experiment with blend modes. Below is the pattern layer set to Multiply. Using this setting would work well if you were placing a pattern over a white or light-colored garment. Good luck!

  • Drawing and Filling Circle and Polygon.

    I have searched about creating these but cannot understand properly. 
    Let SetPixel(X,Y) be the function to set the pixel. I am working in unity3d for drawing on texture.
    Allow time to reverse.

    besides what Armin said
    which setpixel function do you mean ?
    the bitmap.setpixel or the Win32 setpixel ?
    also why would you want it in vb when you don't plan to use vb ?
    I am writing class library for unity3d in vb.net.
    "SetPixel(x,y)" is just a procedure that sets pixel on (x,y). It is enough for drawing.
    I am not dealing with color or anything. Just need to set pixels at right position.
    I tried and found this: (It is to draw non-filled circle)
    Public Function Apply(Texture As Texture2D) As Texture2D Implements Image.Appliments.Apply
    Dim x0 As Integer = Me.X
    Dim y0 As Integer = Me.Y
    Dim x As Integer = Radius
    Dim y As Integer = 20
    Dim RadiusError As Integer = 1 - x
    While x >= y
    Texture.SetPixel(x + x0, y + y0, Color)
    Texture.SetPixel(y + x0, x + y0, Color)
    Texture.SetPixel(-x + x0, y + y0, Color)
    Texture.SetPixel(-y + x0, x + y0, Color)
    Texture.SetPixel(-x + x0, -y + y0, Color)
    Texture.SetPixel(-y + x0, -x + y0, Color)
    Texture.SetPixel(x + x0, -y + y0, Color)
    Texture.SetPixel(y + x0, -x + y0, Color)
    y = y + 1
    If RadiusError < 0 Then
    RadiusError = RadiusError + 2 * y + 1
    Else
    x = x - 1
    RadiusError = RadiusError + 2 * (y - x) + 1
    End If
    End While
    Texture.Apply()
    Return Texture
    End Function
    Allow time to reverse.

  • Black and White With Color Not Working

    I am trying to have the background of my image black and white with the person in color.  I turned black and white on then tried brushing black and white away from the person.  Instead of the full, vibrant color coming back it was a dull color.  Instead, I tried turning black and white off then brushing black and white into the background.  This time, instead of being pure black and white it was black and white with an obvious hint of color.  I have watched plenty of tutorials and know that it is possible to have it be pure black and white in the background with the person in front appearing in full vibrant color.  I just don't know what I am doing wrong that either my vibrant color is looking washed out in one method or my black and white isn't pure black and white in the other method.  When I first turn black and white on the image does go to pure black and white.  Any suggestions?

    See what happens after re-booting.
    Is "Brush Range" set to "All"?
    Try the same adjustments on another Image.
    Try the "Color Monochrome" adjustment and see if it works as expected when brushed in/brushed away.
    Message was edited by: Kirby Krieger -- added a line.

  • How to measure and fill with the same transparency?

    for example creating a fill using Edit > Fill with a random Color and Opacity in the Fill dialog, then later without the original information about the Color and Opacity but just the file, how can I make exact same fill and opacity again?

    White represents 100% opacity, so, yes, 100 minus the black (K) percentage of gray in the mask is the equivalent of opacity. The Info panel can tell you colour and opacity of the displayed composite of visible layers under the pointer/cursor at any time.

  • Shapes Will Not Fill With Color

    For some reason, all of a sudden when I go to make a shape and choose a color, it does not fill. I noticed that the Style box to the right of the color box on the top bar had a white box with a red line through it. I then chose Simple Outer from the drop down box and it still will not fill. Please advise! I am using Elements 10. Thank you! Kelly

    I understand that it is difficult to determine which forum to post in since there are so many. This particular forum (sharing and storage) was created to help those transitioning from Photoshop.com to Adobe Revel. I am moving your post to the correct forum so that it can get proper attention.
    I'll put I this posting in the elements  community so the experts there can help you.
    We also have many other forums relating to other Adobe products
    http://forums.adobe.com/community/
    http://forums.adobe.com
    Out of curiosity, can you tell me how you found our forum page?

  • Upload Cell Filled With Color In Excel

    Hi All ABAP GURUS,
    I have got the requirement to upload the excel file in sap.
    The excel file contains 2 columns-
        Color_Code            Color
            R1                     (Here excel cell will be filled with Red Color)
            G1                     (Here excel cell will be filled with Light Green Color)
            G2                     (Here excel cell will be filled with Dark Green Color) and so on....
    How to save the Color_Code And Color in ZTable. I have the clear idea about BDC that can upload excel file containing data but no idea hoe to upload the Excel file containing Fill Color.
    Kindly guide me in this matter.
    Thanks & Regards,
    Bharti Jain

    Hi.,
    If you are talking abt coouring the column in Report then go here
    http://www.sap-basis-abap.com/abap/color-a-column-value-in-alv-report.htm
    Regards
    GK.

  • Why are my Pictures distorted and not fully filled with color?

    HP ENVY 110 e-All-in-One Printer - D411a.  Why do Printed Pictures come out distorted and and Color not filled in fully?

    FrauSherrie
    SG asked rsayen06 several important questions to get at the core of that user's Premiere Elements issues. So far I do not see any answers to the questions. An the answers will be in those details. Although you have offered your project settings and saying that you have the same problem, they are but a small part of the troubleshooting equation.
    1. What version of Premiere Elements are you using and on what computer operating system is it running?
    2. You say you are putting pictures and music on the Timeline? How many pictures and what are their pixel dimensions? What type of music, what compression and file extension? What is the total duration of the Timeline content?
    3. When you playback the Timeline content in the Edit Mode Monitor are you looking at the rendered or unrender Timeline?
    4. When you say that you see distortion in the pictures...how are they distorted...
    a. from the point of view of pixel aspect ratio, flicker, lines, other?
    b. What do your computer resources look like in the way of installed and available RAM and free hard drive space? Are you getting any error messages associated with any of the project difficulties that you are encountering?
    c. When you get to the burn dialog, what does the Quality Area show for Space Required and Bitrate?
    We will be watching for your follow up.
    Thanks.
    ATR
    Add On...Noted that FrauSherrie has just posted a new thread on the issues cited. Please see the new FrauSherrie thread at:
    http://forums.adobe.com/thread/1252961?tstart=0

  • BitmapData.draw() and displayobject with 3D transformations

    Hi all,
    I have a sprite with some objects in it which are transformed in 3D (positioned and rotated). The objects form a coneshape in such a way that the objects that make up the back are hidden.
    When I use that sprite as a source for the bitmapData.draw() it is drawn from another viewpoint so it seems. In my case the copy is viewed slightly from the bottom and right.
    Bottomline:
    Does anyone know of a way to duplicate the image of a sprite which contains 3D manipulated graphics?
    thanks in advance,
    Manno

    Nevermind:
    var pp:PerspectiveProjection = new PerspectiveProjection();
    pp.projectionCenter = new Point( 0, 0 );
    sphere.transform.perspectiveProjection = pp;
    Where sphere is the object to use as a source in the draw method. It seems OK now it has it's own perspectiveProjection set.

  • Printing black and white with color accent

    I am trying to figure out how the make a photo black and white and just have a flower colored.
    I have Photoshop 9 and am a beginner. Please help!  Thanks.

    1. Open your photo in Full Edit.
    2. Find the smart brush, the one with the gears on it. Choose a black and white style from the thumbnails in the options bar and turn on the Inverse checkbox.
    3. Drag over the flower that you want to keep in color. The rest of the photo will turn black and white.

  • Email activity for soa and bam with pre-built virtualbox images

    Dear OTN,
    i am running pre built virtualbox image for soa and bam and want to run with email activity and configure the email inside the virtualbox can anyone help me with email activity in pre-built virtualbox image.
    Thanks & Regards,
    Pavan

    Hi there
    I have a Technote that shows how the information can be published from EBS to BAM. In addition you could create an end to end visibility across the products e.g. B2B - BPEL - EBS - Financials etc by raising the events to BAM .
    There is no out of the box dashboards available today. However, i have a number of customers who are doing this use case by themselves or through some SI/Oracle consulting.
    can we contact you offline to discuss your requirement?
    http://www.oracle.com/technology/products/integration/bam/11g/technotes11g/whitepaperBAM_E-BusinessSuiteIntegration.pdf
    There are certified adapters available for EBS to FM as well.
    Regards
    Payal
    Edited by: PayalS on May 21, 2010 4:25 PM

  • IMac OSX 21.5 late 2010, had MTN Lion on it. Prob with thousands of my photos in IPhoto all mixed up and intermingled with thousands of odd images I had not seen before. After trying to erase them, too numerous, I used original disk for disk utility. Disk

    Utility had issues with erasing disk. It took 36 hours and then said it was a failure. I tried repairing and verifying and partitioning. Finally, I used the original disk to install the system. It installed Snow Leopard. I was unable to install the 2nd disk ILife items, so I repurchased those. I thought I was all set but it would not upgrade past 10.6 or something. After it is all set up, I realize there is nothing on the computer. The updates were in download folders and in reading the install logs, it said the install disc was read only and the system was installed from somewhere else and then it was reaped and something about a sandbox and it seemed important that all the Asian languages were added in, even though I unchecked that option. All these odd programs and windows are on there, which I do not use and do not want on there and do not see it on there. So, I tried this several more times, it appears someone is using the Root user. I tried to disable the root user as I do not understand how to set it. Last night, I took the main partition that I put everything on and made me the owner and took over that whole disk. Then the other two were locked, do I ejected them. Then I wanted to erase 4 things - an iDisk an some other trash and the trash is suddenly emptying 989 items, I think were the logs. So, I turned it off. What is going on? I was unable to fix the install disk. The permissions were not repairable on the partition, it was verified as being ok though. Has someone taken over my computer? How can I get rid of them and get it fixed? It has affected my iPad and my iPhone 5. I really need these devices. I am an artist and need to take and post photos of my work. Is this Chinese people doing this and are they nearby?  I did notice they wanted me to sign up for mo ole me. in the logs  it even said, no [email protected]. And no password access at that address.  So, I was also not able to update to Mountain Lion and Icloud again. at one point it looked like I had. i downloaded everything I purchased that was in Icloud to Itunes and it showed the lion in Mail but there was no cloud icon and Mountain Lion said to install, meaning it was not installed. System information confirmed this. oh, and my main disk in disk Utility is named with an unchangeable name that is the serial number of the mac and it says it is an in/out sata media drive. Please, please help me.

    1. If you break your post into paragraphs it is much easier to read.
    2. I have no idea what your post is referring to, and how - if at all - it relates to iPhoto.
    3. It's a good idea to re-read what you've posted, and ask yourself how it might look to someone who doesn't know you and doesn't know what's going on with your machine.

  • Mavericks wont save and open with my preferred desktop image

    After installing Mavericks my iMac opens with the "rolling surf" desktop. I can then start my preferred desktop from a saved 'photo but when I retsart the iMAc it reverts to "rolling surf". How can I get it to remeber to open with MY choice rather than Apple's?

    Hi, as dgriffiths-leics-gov-uk said, you have to sign your applet, check the Jar files, and signing applets tutorials at java's site, or else the following URL:
    [http://forum.java.sun.com/thread.jsp?forum=54&thread=383859]
    ...there was a posted message which I replied with all the process condensed to sign and add permissions to an applet, including the use and creation of the Jar file, its way to be signed; and, the HTML code you shall use. That way you can use
    JFileChooser class and its methods in your class; therefore, the File Choosing dialog will be shown and you'll be able to Open and Save user files.

Maybe you are looking for

  • How to set "Output folder" and "Outputfolder URL" in Flasbuilder 4b1 for combined Java/Flex project with WTP?

    Hi, how can I set the "Output folder" and "Output folder URL" in Flasbuilder 4b1? In Flexbuilder 3 I can do this under Project Properties/"Flex Build Path"  Under "Flex Build Path" in F4b1 I can see the settings, but they are not editable. A message

  • I can't sync music to my iPhone 6?

    Ive tried syncing new playlist from iTunes to my iPhone 6 and for some reason its not working. is anyone else experiencing this issue? My contacts, calendar dates and photos work fine but I can't sync my music for some reason.

  • Software to Monitor CPU and Fans

    I have an MSI 785G-E53 with a Phenom II x2 (with all 4 cores unlocked). What program can I use to monitor the CPU core temps, fans, maybe even the hard drives too? I tried both speedfan and coretemp and neither looked like they pulled the CPU core te

  • Unable to perform call transfer & call park through SIP Trunk (SKYPE)

    The Scenario is: I have set up a SIP trunk to SKYPE and we are able to make outbound call to a number via SIP Trunk. After the call is established, when we tried to make call transfer, the call DROP and the phone at the other end shows error "Temp Fa

  • I bought student version for cc and still can't use the apps

    I bought student version for cc and still can't use the apps and when i sign in only the free CC membership appears I also chick the bank the transaction was successful and  i only resieve a confirmation email. i need to work with these apps so badly