Filling a Rectangle with a gif as pattern

Hi!
How do load and fill a Rectangel with a gif picture as pattern?
I have looked at the following html page.
http://java.sun.com/docs/books/tutorial/2d/display/example-1dot2/ShapesDemo2D.java
Regards
Johan

Look at this applet.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class Pat extends Applet 
           Image  i1;
public void init()
     try
          URL u1 = new URL(getCodeBase(), "game1.gif");
          i1 = getToolkit().getImage(u1);
          MediaTracker tracker = new MediaTracker(this);
          tracker.addImage(i1,0);
          try   {tracker.waitForID(0);}
          catch (InterruptedException e){}
     catch(Exception e){};
public void paint(Graphics g)
     super.paint(g);
     g.drawImage(i1,10,20,10+100,20+100,0,0,100,100,null);     
public void update(Graphics g)
     paint(g);
Noah

Similar Messages

  • Filling a rectangle space with a photo image in an applet

    I'm creating a web page that will display an image of a persons wall and I want to be able to use the mouse to draw a rectangle on the image of the wall and fill the space with a selected photo image.
    I have found out that you can use the MousePress and MouseDrag events to draw a rectangle and "paint" the rectangle in a componant inside the applet. But I'm not sure how to fill the rectangle with an image instead of a color. Can someone tell me if there is an AWT or Swing method that can do this?
    I was thinking of filling the applet window with a label component and then filling it with the wall image. Then some how using the coordinates given from the drag event to creat a new label component and filling it with the photo image. Hope I'm on the right path. Thanks for all the help.

    Great thanks, I looked it up in the docs and I found one that will work for me but I'm not sure how to use the arguements. It's the drawImage method that uses the scalebility. This would work perfect seeing as though the image to be posted will be various sizes. Can any one explain this method in more detail for me. Thanks again.

  • How to Trim Rectangle with text to create reflection?

    Hello Everyone,
    I am realtively new to Illustrator and I am facing a problem that I am hoping some expert here can resolve. I have some text and I have converted it to outlines. Now I want to create shine on it. I want to fill a rectangle with white color and then clip it with text to give reflection effect but I can't figure out how to do it. I have selected my text and rectangle and tried all options in path finder tool but nothing seems to work. Please guide me how can this be done.
    Regards,
    Afraz Ali

    Afraz Ali,
    If you want to have the colour/colours/colour transition of the rectangle where the text is is nothing outside it, in other words colour the text with the colouring of the rectangle, you may:
    Use Live Type over the rectangle, select both, and Object>Clipping Mask>Make.
    With outlined type, you have to turn the lettershapes into a Compound Shape first.
    As you can see, it is simpler to just use Live Type, and it is editable.

  • Rectangles with colors

    <mx:Canvas id="b1" x="10" y="10" height="40" width="300" borderStyle="solid" borderColor="black"/>
    to add rectangles side by side inside this canvas i wrote the following code
    for(var i:int=b1.x;i<b1.x+b1.width;i=i+15)
                        var line1:UIComponent = new UIComponent();
                        var lineThickness1:Number = 1;
                        var lineColor1:Number = 0x000000;
                        var lineAlpha1:Number = 1;
                        line1.graphics.lineStyle(lineThickness1,lineColor1,lineAlpha1);
                        line1.graphics.moveTo(i,b1.y);
                        line1.graphics.drawRect(i,b1.y,15,b1.height);
                        this.addChild(line1);
    now I want to fill those rectangles with colored rectangles starting to ending
    i pass the units then units*15 will be calculated and the covered rectangles will be populated with colored rectangles for that i wrote the following code
                             var c:UIComponent = new UIComponent();
                            var xposstr:String = arr1.getItemAt(arr1.length).toString();
                            var xpos:int = parseInt(xposstr);
                           c.graphics.beginFill(0xFFCC00,1);
                            c.graphics.drawRect(xpos,0,numUnits*15,b1.height-2);
                            c.graphics.endFill();
                            b1.addChild(c);
                            arr1.addItem(c.x+numUnits*15);
    arr1 is the ArrayCollection
    but iam not getting the required output

    This code draws rectangle (random background color),
    var colors: Array = [0x0000FF, 0x00FF00, 0xFF0000, 0xFF00FF]
    for(var i: int = 0; i < b1.width; i = i + 15) {
         var lineThickness1:Number = 1;
         var lineColor1:Number = 0x000000;
         var lineAlpha1:Number = 1;
         var bgColor: uint = colors[Math.floor(Math.random() * colors.length)];
         var g: Graphics = b1.graphics;
         g.lineStyle(lineThickness1,lineColor1,lineAlpha1);
         g.beginFill(bgColor, 1.0);
         g.moveTo(i, 0);
         g.drawRect(i, 0, 15, b1.height - 1);
         g.endFill();

  • Filling an object with a pattern without distortion?

    I have this camo pattern:
    wich already tiles seemlessy but when i turn it into a swatch it won't tile. it distorts the pattern and blows it up instead of using it as is and tiling:
    what is the problem here? can i scale it in some option menu? can i control the orientation? im creating a vector based logo, is this the right way to go about filling the object with this pattern?
    i want it to be scaled and tiled. what is the best way to go about it? what would u do? thanks in advance

    yup i thought so. it HAS to be vector based.
    it does not have to be vector, it can be jpeg or gif, but it has to be embedded...as for not using it in a logo, Scott can explain that.
    255x247 px
    the object is any size as its a vector. How are u filling yours? photoshop then a clipping mask?
    I meant the size of the camo image in relation to your vector object, not the actual size in pixels.
    in this sample I grabbed a GIF, embedded it, dragged it to the swatches palette, sent the image to back, then filled both the small object and the big object with the gif-embedded swatch, just to illustrate what happens with the size position.

  • Filling Text art with gradient or pattern

    Hello all,
    I'm trying to fill some existing arts (path, text, compound) with a just created gradient or a pattern loaded in the swatch
    To achieve that I'm trying to change the path style:
    GetPathStyle (myArt, &pathArtStyle);
         pathArtStyle.strokePaint = false;
         pathArtStyle.fillPaint = true;
         pathArtStyle.fill.color.kind = kGradient;
         pathArtStyle.fill.color.c.b.gradient = myGradient;
    SetPathStyle (myArt, &pathArtStyle);
    This works for kPathArt,
    but nothing happens for kTextFrameArt or kCompoundPathArt.
    How can I program this ?
    thanks in advance
    PS: I also tried to program the procedure "How to Fill Text with a Pattern or Gradient in Adobe Illustrator" described for illustrator UI, w/o success
    PS: I have similar problem when trying to create a clipping using SetGroupClipped()  (see AI function reference) while the clipping path is a text or compound. No clipping is done.

    To fill text with a gradient or pattern youi can do two things, either
    1) outline your text (Type > Create Outlines) then click on the pattern or gradient swatch you require. For easier control of gradients it is best to make a compound path of all the letters. This method is not editable because the type is no longer live.
    2) If your type needs to be live do the following: Type your text and colour it None (no fill, no stroke). Then Appearance panel flyout menu; Add New Fill and click on your swatch.

  • Fill a rounded rectangle with a gradient paint with "new RoundRectangle2D"?

    Hello,
    at the moment I have to do a lot of Java2D to draw a customized GUI. Now it comes to a simple task, filling a rounded rectangle with a gradient paint. I have a solution for this - but I don't know if it is bad to do it this way:
    private void drawBackground( Component component, Graphics2D graphics2d ) {
         int w = component.getWidth() - 1;
         int h = component.getHeight() - 1;
         graphics2d.setPaint( gradientPaint );
         RoundRectangle2D backgroundShape =
              new RoundRectangle2D.Float( 0, 0, w, h, 10, 10 );
         graphics2d.fill( backgroundShape );
    }This is very easy and it works. The backdraw is, that on every call of "drawBackground", which is called on a repaint() method by Swing, a "new RoundRectangle2D.Float" will be created. I don't know how "expensive" it is to create a new RoundRectangle2D. On the other hand, I don't know how to fill a rounded rectangle with a gradient paint without a RoundRectangle2D.
    When I do it this way, I worry that at a later time, when I created a lot of custom components that all create shapes on a repaint, the GUI may become horrible slow or has a huge memory footprint.
    Well, I would like to hear some kind of "this is okay" (maybe because those Shape implementation are all not very memory consuming and the instanciation in Java is not very time consuming) by you Java2D experts :) Or, of course, how I could do it better.
    Thanks a lot for your help!

    patb1 wrote:
    on every call of "drawBackground", which is called on a repaint() method by Swing, a "new RoundRectangle2D.Float" will be created. I don't know how "expensive" it is to create a new RoundRectangle2D.
    When I do it this way, I worry that at a later time, when I created a lot of custom components that all create shapes on a repaint, the GUI may become horrible slow or has a huge memory footprint.You could do as many UI delegates in the Swing code do with Rectangles: maintain a RoundRectangle2D as a field and set its attributes when it is to be painted (setRoundRect(double x, double y, double w, double h, double arcw, double arch)).
    db

  • How to use a scaled object(MC) to fill the background with the new properties

    So lets say i have a stage 300 to 200 and all object that i have are for this dimensions.Also have an pattern function that fills the background.
    But the user is thinking of resizing the stage to lets say 1024 to 480 (he switched from a phone to a tablet).And now the scale of the objects in the tablet screen are more than 3times before(when seen on the Phone)
    How do i save the current new size object and use it in the creation of the new background (the 1024x480).
    currently i have this :
    public static const GAME_ORG_WIDTH:uint = 300;
    public static const GAME_ORG_HEIGHT:uint = 200;
    public function MainClass_road() {
                                  addEventListener(Event.ADDED, init);
                        public function init(e:Event):void{
                                   stage.scaleMode = StageScaleMode.NO_SCALE;
                                     stage.align = StageAlign.TOP_LEFT;
                                     stage.addEventListener(Event.RESIZE, setUpScreen);
                        public function setUpScreen(ev:Event):void{
                                  stage.removeEventListener(Event.RESIZE, setUpScreen);
                                  if(stage.fullScreenHeight > stage.fullScreenWidth){  
                                            gameStageWidth = stage.fullScreenWidth;
                                gameStageHeight = stage.fullScreenHeight;
                                  }else {
                                            gameStageWidth = stage.fullScreenHeight;       // 480
                                            gameStageHeight = stage.fullScreenWidth;                     //1024
                                  rescaleRatio = gameStageWidth / GAME_ORG_WIDTH;  
                                  //rescale every object, ie:
                                myC.scaleX = myC.scaleY =   rescaleRatio;
                       //start filling the Background with the pattern
                                       tileBgF();
    and then I use the while loop for filling the screen/background
    public function tileBgF(e:Event=null):void {
                                                      var bgClip = MyC;
                                                      var i:int = 0;
                                                      var j:int = 0;
                                                      while (bgClip.x < stage.stageWidth) {
                                                                bgClip = MyC;
                                                                while (bgClip.y < stage.stageHeight) {
                                                                          bgClip = MyC;
                                                                          tileLayer.addChild(bgClip);
                                                                          bgClip.x = bgClip.width * i;
                                                                          bgClip.y = bgClip.height * j;
                                                                          j++;
                                                                j = 0;
                                                                i++;
                                                      addChildAt(tileLayer,0);
    why does it give me
    Line 52
    1120: Access of undefined property MyC.
    in public function tileBgF
    and further more.After filling the background/screen with the pattern , how do i save it all like one big bitMap  so i can use /add it after time without doing all the checking of screen and things again.

    and is it better to use
    stage.fullScreenHeight
    in the while loop or leave it like it is ,or its irrelevant

  • How to fill a rectangle, which has already been written in?

    Hi guys:)
    As you can see, I have a rectangle with words inside it and I want to fill it with colour, problem is I don't know how to.
    Thanks!

    It would help to see the layers panel and the appearance panel as it would show if the text is live type or rasterized. If the latter it may be easier to just put a rectangle over top of the text.
    If it is live type you just need to select the text layer then use the text tool.

  • 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.

  • Draw Rectangle with red border and transparent center

    I need a little help on the rectangle object.  I need to draw a rectangle with a transparent middle and a red boarder with a thickness of 2:
    Code:
    private void InitializeRectangle(Rectangle rectangle, CellLayoutBox cellBox)
    rectangle.Fill = new SolidColorBrush(Colors.Transparent);
    rectangle.StrokeThickness = 1;
    rectangle.Width = cellBox.Width;
    rectangle.Height = cellBox.Height;
    Canvas.SetLeft(rectangle, cellBox.Left);
    Canvas.SetRight(rectangle, cellBox.Top);
    I know I am missing the mark here, but it I can't seem to get a rectangle with a transparent fill and stroke of a different color even if I change the Colors.Transparent to another color. Any help is appreciated.

    @katghoti,
    Thanks for sharing the result back to forum.
    Best regards,
    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How can I move a rectangle with key?

    I try to control a rectangle with left and right key to move, but failed and need help to make it work. thanks!
    var cx:Number;
    var cy:Number;
    var fang:Rectangle=Rectangle{
         x:bind cx  y:bind cy
         width:50  height:50
         fill:Color.BLUEVIOLET
         onKeyTyped: function( e: KeyEvent) : Void {
                    if(e.code==KeyCode.VK_KP_LEFT){
                             cx++;
                             println("left pressed!");
                    if(e.code==KeyCode.VK_KP_RIGHT)
                              cx--;
    Stage{
        width:200
        height:400
        scene:Scene{
             content:[fang]
    }Edited by: Phoenix2006 on Sep 14, 2009 8:18 PM
    Edited by: Phoenix2006 on Sep 14, 2009 8:21 PM

    You will have to invoke requestFocus() on Rectangle so as to gain focus. You may try below code..
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.input.KeyCode;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.Rectangle;
    var cx:Number;
    var cy:Number;
    var fang = Rectangle {
        x:bind cx
        y:bind cy
        width:50
        height:50
        fill:Color.BLUEVIOLET
        onKeyReleased: function(e) : Void {
            if(e.code == KeyCode.VK_LEFT) {
                cx--;
            } else if(e.code == KeyCode.VK_RIGHT) {
                cx++;
            } else if(e.code == KeyCode.VK_UP) {
                cy--;
            } else if(e.code == KeyCode.VK_DOWN) {
                cy++;
    Stage{
        width: 200
        height: 400
        scene: Scene {
            content: [ fang ]
    fang.requestFocus();

  • Problem with animated .gif

    I have a problem with animated gifs. So if I set a animated gif as background and a button is over it as in the example below, then everytime the animation goes on the button disappears until I go over it with the mouse. So what can I do to solve this?
    import java.awt.Color;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    public class FrameBackImage {
              public static void main(String args []){
                   final JFrame frame = new JFrame("Frame");
                   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   frame.setSize(400, 400);
                   frame.setResizable(false);
                   frame.setLayout(null);
                   java.net.URL imageURL = ImageApp.class.getResource("animatedw.gif");
                   ImageIcon imageIcon = new ImageIcon(imageURL);
                 final JLabel label = new JLabel(imageIcon);
                 label.setBounds(0,0 , 400, 400);
                 frame.getLayeredPane().add(label);
                 JButton button = new JButton ("Exit");
                 button.setBounds(200, 129, 60, 60);
                 button.setBackground(Color.black);
                 button.setForeground(Color.white);
                 frame.add(button);
                 button.addActionListener(
                 new ActionListener(){
                        public void actionPerformed(ActionEvent arg0) {
                             System.exit(0);
                 frame.validate();
                  frame.setVisible(true);
    }

    In the future, Swing related questions should be posted in the Swing forum.
    Your usage of the getLayeredPane() method is something I've never seen before, so I don't know if thats the problem or not.
    How to display a "background image" is asked all the time in the Swing forum. So to familiarize yourself with the forum you can try searching the Swing forum. Using the keywords I highlighted would be a good place to start.

  • Help with animated gif background once opened in Photoshop c33 extended

    I often work with animated Gif's and a
    adding doggies etc to the top layer.
    I am having a problem with animated Gif with (existing transparent) background when saving from the web and opening in Photoshop cs3 extended it is changing the background to White automatically ?  ( which is not what I want)  I would like to know how to keep in the same format with the tranparent or even change to black as that is the background on my website.....do not know why it is converting it to white in photoshop or how to change....Thank you advance!

    Thank you so much....after many hours playing with ....went right too and worked perfect!!  Thank  you !!

  • Problems with animaged gif's

    Hi, I'm trying to draw a ComboBox with animated gifs in the selection list.
    And the problem is that the gifs are painted but always with the same image. Here it is part of the source code of the ListCellRenderer class.
    In the paint(Graphics g) function I have:
    "g.drawImage(((ImageIcon)icon).getImage(),rect.x,rect.y,this);"
    and if I use the following we've the same result
    "icon.paintIcon(this,g,rect.x,rect.y);"
    It is also rewritten the function: "imageUpdate" and it makes the gif to be repainted every 100 ms (that's ok) but always paints the same image so it doesn't animate.
    Any ideas?

    The solution:
    public Component getListCellRendererComponent(JList list, Object value,
    int index, boolean isSelected, boolean cellHasFocus) {
        JLabel tmpLabel = new JLabel();
        if (value instanceof ImageIcon) {
          ImageIcon tmpIcon = (ImageIcon)value;
          tmpIcon.setImageObserver(list);
          tmpLabel.setPreferredSize(new Dimension(tmpIcon.getIconWidth(),tmpIcon.getIconHeight()));
          tmpLabel.setIcon(tmpIcon);
        else
          tmpLabel.setText(value.toString());
        return tmpLabel;
    }The problem was to set "list" as the ImageObserver of the icon
    Bye...
    Olaso

Maybe you are looking for