Fill Shape With Picture? student

Hello,
Is there a way to draw a shape and then fill it with a picture from a file?
Also, I'm not sure if that is the best way to put pictures into the program I am making... any advice?
- Jason

import java.awt.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.*;
public class ShapeImage {
    private JScrollPane getContent(BufferedImage source) {
        BufferedImage framed = getFramedImage(source);
        Box box = Box.createHorizontalBox();
        box.add(Box.createHorizontalGlue());
        box.add(new JLabel(new ImageIcon(source)));
        box.add(Box.createHorizontalGlue());
        box.add(new JLabel(new ImageIcon(framed)));
        box.add(Box.createHorizontalGlue());
        return new JScrollPane(box);
    private BufferedImage getFramedImage(BufferedImage image) {
        int w = 160, h = 160;                   // shape/frame size
        int type = BufferedImage.TYPE_INT_RGB;  // other options
        BufferedImage out = new BufferedImage(w, h, type);
        Graphics2D g2 = out.createGraphics();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        Ellipse2D circle = new Ellipse2D.Double(0,0,w-1,h-1);
        // Center image in circle frame.
        double x = (w - image.getWidth())/2;
        double y = (h - image.getHeight())/2;
        AffineTransform at = AffineTransform.getTranslateInstance(x,y);
        g2.drawRenderedImage(image, at);
        // Mask out image pixels that lie outside of the circle disk.
        Area mask = new Area(new Rectangle(0,0,w,h));
        mask.subtract(new Area(circle));
        // Use the desired background color.
        g2.setPaint(UIManager.getColor("Panel.background"));
        g2.fill(mask);
        // Draw the circle/shape frame.
        g2.setPaint(Color.red);
        g2.draw(circle);
        g2.dispose();
        return out;
    public static void main(String[] args) throws IOException {
        BufferedImage image = ImageIO.read(new File("images/cougar.jpg"));
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new ShapeImage().getContent(image));
        f.pack();
        f.setLocation(200,200);
        f.setVisible(true);
}

Similar Messages

  • How to fill shape with pattern... and cut outline?

    I have an old plotter that works great for making drawings. I can fill a shape with a pattern, convert the pattern to outlines (or strokes) BUT my problem is that the outline of the original shape remains, and this will be plotted. I do not want an outline of the original shape, I want the pattern to create the shape. Any ideas? Also, shape stroke remains part of the art (even if stroke = none before object/expand/ungroup/divide)

    aha!
    made scribble
    expanded scribble
    put shape in front
    select all, ctrl+7 (masked scribble to shape)
    pathfinder/crop
    solved. thanks! sishamDSS!

  • Fill shape with pen tool

    Hi there,
    this might be a very simple question, but couldn't figure it out ..
    I made a Title in Premiere and I want to draw a shape with the pen tool.
    However this only results into a shape with line instead of it being filled.
    So my question: how to draw a filled shape in Premiere Pro with the pen tool?
    Thanks in advance

    Set Graphic Type to Filled Bezier, that will fill the shape.

  • Fill shape with a pattern

    Hi,
    I am drawing some shapes using java.awt.Shape, java.awt.geom.Area and java.awt.geom.GeneralPath and would like to know whether it's possible to fill these closed shapes with a color - or even better - with a pattern.
    Thanks!

    er, yes, why not?
    http://java.sun.com/docs/books/tutorial/2d/geometry/strokeandfill.html
    -Puce

  • Fill shape with image

    Hi,
    I have drawn a curved box and wish to fill it with and image. I'm having trouble with this as the image is a rectangle and the box has curved edges. Is there any way which you can fill the box with the image. It will not matter if edges of the image are cut out.
    Thanks in advance
    Euan

    > I'm having problems copying layers.
    I take it this is a separate question? (no need to copy layers for what I suggested before)
    Highlight a layer in the layers palette, then press CTRL+J (windows) or Command+J (Mac) if you want a duplicate.
    Otherwise, highlight the layer, press CTRL+A (windows) or Command+A(Mac) , then CTRL+C (windows) or Command+C (Mac) and then you can paste it where you want.

  • Fill shape with 2 solid colors

    Hi,
    I was wondering if there is an easy way to fill a roundRectangle2D with 2 solid colors. For example that 1/3 is blue and the other 2/3 is green? I've looked in the java graphics2D api but can't find anything. GradientPaint isn't what I'm looking for, so is there any other easy option.
    Or is it the hard way and you need to draw several shapes on top of each other?
    class EventPanel extends JComponent{
        @Override
        protected void paintComponent(Graphics g){
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g.create();
            Double widthRect = (double) this.getWidth();
            Double heightRect = (double) this.getHeight();
            Double arc = widthRect / 20.0;
            Float strokeSize = 1.0f;
            Double offset = strokeSize / 2.0;
            Double adj = offset * 2;
            RoundRectangle2D.Double roundRect = new RoundRectangle2D.Double(offset, offset, widthRect - adj, heightRect - adj, arc, arc);
            RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setRenderingHints(rh);
            g2.setPaint(new Color(30, 144, 255, 80));
            g2.fill(roundRect);
            g2.setPaint(Color.BLACK);
            g2.setStroke(new BasicStroke(strokeSize));
            g2.draw(roundRect);
            g2.dispose();
        }Similar to this: Example Don't mind the quality. Not good at art.
    Edited by: Kligham on 26-aug-2010 22:55
    Edited by: Kligham on 26-aug-2010 22:58
    Edited by: Kligham on 26-aug-2010 23:01

    Or is it the hard way and you need to draw several shapes on top of each other?What's so hard about that? But if you're looking for an alternative approach, you can do it with Graphicd$setClip(...)
    GradientPaint isn't what I'm looking forWhat about LinearGradientPaint?import java.awt.*;
    import javax.swing.*;
    public class StepGradientPaint {
      float[] fractions = {0F, 0.5F, 0.50001F, 1F};
      Color[] colors = {Color.RED, Color.RED, Color.GREEN, Color.GREEN};
      Paint paint = new LinearGradientPaint(0F, 0F, 200F, 0F, fractions, colors);
      public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
            new StepGradientPaint().makeUI();
      public void makeUI() {
        JPanel panel = new JPanel() {
          @Override
          protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g.create();
            g2.setPaint(paint);
            g2.fillRect(0, 0, getWidth(), getHeight());
            g2.dispose();
        panel.setPreferredSize(new Dimension(200, 200));
        JFrame frame = new JFrame();
        frame.add(panel);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }db

  • Fill Shape with text

    I'm trying to Fill Number 9 with text but I always get this :
    I want to have the circle inside without text !
    Someone Can help me ?
    Sorry Im newbie  :/

    I know you know a lot more about the internals than I do, Chris, and I hate to be argumentative, but I'm just not seeing the difficulty...
    Consider that the text placement code as written today can deal with the following (hastily drawn path).
    And as Paulo points out, Photoshop clearly already knows what's "inside" and what's "outside" a complex path.
    Emil makes a good point about the readbility suffering if one has to follow it across breaks in the figure...
    Still, who's to say whether someone wouldn't come up with a good use for this.  Bottom line is this - here you have a user expecting Photoshop to do something that's expected, and it's falling short because of the implementation and not allowing him to express his creativity the way he wants....
    This exercise DID bring one new idea to mind possibly for hhtun...  Try using a stencil font!
    -Noel

  • Recently, when I create a new album (untitled), it immediately fills with picture either from the album above it or, if I have a Faces collection open, with the pictures from that collection. Why and how do I fix it?

    Recently, when I create a new album (untitled), it immediately fills it immediately fills with picture either from the album above it or, if I have a Faces collection open, with the pictures from that collection. Why and how do I fix it?

    When a new album is created it will fill with whatever is in the right hand window,  If you're in the Events or Photos mode it will contain all photos in the library.  Yes, strange behavior.
    OT

  • Cannot fill a rectangular shape with Color

    HI,
    I cannot fill a rectangular shape with color. I know it was working at some point. I checked the ID help, and did a search here with no results.
    I have the tool bar set correctly I think (see below). The object isn't behind other objects either, - that I can see. I do see it when I use the scroll bar so it's there somewhere. (see Pink box below).
    Any ideas profound or otherwise?
    Thenk Yew.

    You haven't got 100% transparency applied to it?  Then it might appear while scrolling because of a slightly delayed display.  That's all I can think of at the moment...
    The other thing to try if you suspect an individual document is playing up is to export it to inx or idml and open that.  Then another thing is to try replacing your preferences.

  • I made a card using the iPhoto and when I click to buy it, it says that I did not fill all the frames with pictures, even though I did and have checked multiple times. Please help, it's for Mother's Day.

    I made a card using the iPhoto and when I click to buy it, it says that I did not fill all the frames with pictures and that I need to in order to purchase it, even though I did and have checked multiple times. Please help, it's for Mother's Day.

    Before ordering your book preview it using this method - http://support.apple.com/kb/HT1040 - and save the resulting PDF for reference - the delivered book will match it.
    LN

  • HT5085 I have nearly filled my iCloud storage with pictures. If I subscribe to iTunes match, will I still be able to access music via the cloud?

    I have nearly filled my iCloud storage with pictures. If I subscribe to iTunes match, will I still be able to access music via the cloud, or will I have to buy more storage space? Cheers.

    Yes, but... you'll have to first index her music through your iTM subscription. So... you'd have to add her music into your own library first. Which.... would defeat the point of iTM I suspect in your case.

  • How to draw a shape with line tool then fill with colour

    How can i draw a shape with the line tool and then fill it with colour

    Click and drag from one anchor point to the next, making sure that each new line segment begins where the last one ended. The Line Tool will snap onto the anchors.
    Once you're done creating what looks like a closed path, the lines are still separate objects. To combine them into one path, select them all and press Ctrl/Cmd+J (for Join) or via the menu select Object > Path > Join.
    The Pen Tool can be used in a similar manner, but each segment will be a continuation rather than a separate object. The last (closing) click will be indicated by a tiny circle on the mouse pointer.
    If you make an open path, Ai will still "fill" it with a fill color by assuming a straight path between the last open anchor points. Individual straight paths, however, such as those drawn by the line tool, have no "inside", so they won't show the fill color even if you have assigned one.
    Allen

  • Fill shape drawn with pen tool

    There are three posts dealing with this issue and each time the person who posted the problem said they figured it out but did not say what they did.  Here is the problem:
    I draw a shape with the pen tool in Flash CS4.  I made sure the shape was closed.  But, I cannot fill the shape no matter what.  Paint bucket tool does not work.  Whatever I do, I get the red diagonal line on the fill color.  I can fill a shape with the rectangle or oval tools but not the pen tool.
    Please help.  Thanks.

    Thanks for your help.  I tried what you suggested but the union selection was grayed out.  I was in the drawing object mode.  But after fooling with it for a bit the following worked (I'm still not sure why):
    I double clicked on the object with the selection tool.
    I then selected a fill color in the property panel and it filled in.
    However, I cannot replicate this.  I tried drawing another shape with the pen tool and cannot fill it in.  I tried converting it to a symbol and that did not work either.  I must have done something to the original shape that allowed me to fill it in last time I fooled with it.

  • PE 7-  Help with Filling Shapes

    Having trouble with something pretty basic (I thought)...
    How do I fill a shape (rectangle, circle, etc) that I create on a Title from the toolbar?
    When I select one of the shape tools, I can create one in the Title area but I can't figure out how to fill it with color.
    Tried COLOR PROPERTIES but FILL is not 'active'.
    Appreciate some enlightenment on this.
    Thanks!
    John
    sr71 -at- comcast.net

    My mistake... OOPS!
    I selected a TITLE that must have had a transparent background (BLUENOTES_LWR_THIRD).
    I usually start by selecting any TITLE then deleting the default graphics in it to create a black b/g.
    From there, I make copies of the b/g and use those for my custom titles (Intro, end, etc.) which I add TEXT to.
    Once I selected GENERIC1_TITLE, and deleted the default graphics, I was able to add RECTANGLE to it
    and modify the fill color.
    I know there's probably an easier/better way to create titles; just haven't had the time to 'explore' more.
    Thanks for the quick reply!
    John

  • I cant locate a file a had filled with pictures think i may have deleted is their anyway to recover it

    i cant locate a file a had filled with pictures think i may have deleted is their anyway to recover it

    Hi t,
    First, don't create or change any files. The more you do, the less chance you have of recovering any data. Google for Mac data recovery applications. There are several. At least one allows you to use it to see if you can recover data, without paying for it. If you decide to recover it, then you have to pay for the app in order for it to do the recovery.

Maybe you are looking for

  • Printing with an HP Laserjet P1009 through a time capsule

    hello I have an HP Laserjet P1009 and a macbook Pro. I can print from the macbook to the laserjet just fine if it is connected directly (USB), but I am trying to connec the printer to my time capsule and print through there. I saw a previous post wit

  • CR2 files from Canon 70D in Elements 11 on windows Vista

    I cannot get Photoshop 11 to recognize (open) CR2 files from my Canon 70D camera. Running Windows Vista. Is there an update for this for Vista.

  • CS2 Installs successfully on Windows 7 but says invalid Serial Number

    Hi all, I just bought a new Dell with Windows 7.  When I installed the CS2 Premium software, it accepted my serial number and it also activated the software successfully at the end of installation.  When I check my online Adobe account, it shows the

  • Revenue for a material for a period

    How can we find the revenue for a material for a particular period? Is there a standard report that shows the billing data for material with the list of customers Edited by: SATHISH KUMAR ARUGA KEERTHI on Sep 25, 2009 9:08 AM

  • Can you export only certain dates or events?

    I use iCal on my laptop to organize my life, but my job wants me to be on Oracle too. So I export my iCal "work" calendar and import it in Oracle. Fine. But then I add something to my calendar, and I want to put it on Oracle too. if I export my "work