Drawing Buffered Images

Discussion in 'Java' started by Chase Preuninger, May 19, 2009.

  1. BufferedImage img = new BufferedImage(50 * text.length(), 100,

    BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g = img.createGraphics();
    g.drawRect(0, 0, img.getWidth()- 10, img.getHeight() -10);
    g.setBackground(Color.WHITE);


    Why is the background still black?
    Chase Preuninger, May 19, 2009
    #1
    1. Advertising

  2. Chase Preuninger

    Mark Space Guest

    Chase Preuninger wrote:
    > BufferedImage img = new BufferedImage(50 * text.length(), 100,
    >
    > BufferedImage.TYPE_3BYTE_BGR);
    > Graphics2D g = img.createGraphics();
    > g.drawRect(0, 0, img.getWidth()- 10, img.getHeight() -10);
    > g.setBackground(Color.WHITE);
    >
    >
    > Why is the background still black?



    Did you read the manual?

    "public abstract void setBackground(Color color)

    Sets the background color for the Graphics2D context. The
    background color is used for clearing a region. When a Graphics2D is
    constructed for a Component, the background color is inherited from the
    Component. Setting the background color in the Graphics2D context only
    affects the subsequent clearRect calls and not the background color of
    the Component. To change the background of the Component, use
    appropriate methods of the Component. "
    Mark Space, May 19, 2009
    #2
    1. Advertising

  3. Mark Space wrote:
    > Chase Preuninger wrote:
    >> BufferedImage img = new BufferedImage(50 * text.length(), 100,
    >>
    >> BufferedImage.TYPE_3BYTE_BGR);
    >> Graphics2D g = img.createGraphics();
    >> g.drawRect(0, 0, img.getWidth()- 10, img.getHeight() -10);
    >> g.setBackground(Color.WHITE);
    >>
    >>
    >> Why is the background still black?

    >
    >
    > Did you read the manual?
    >
    > "public abstract void setBackground(Color color)
    >
    > Sets the background color for the Graphics2D context. The background
    > color is used for clearing a region. When a Graphics2D is constructed
    > for a Component, the background color is inherited from the Component.
    > Setting the background color in the Graphics2D context only affects the
    > subsequent clearRect calls and not the background color of the
    > Component. To change the background of the Component, use appropriate
    > methods of the Component. "
    >


    But you probably shouldn't use Graphics.clearRect() any more because
    "Beginning with Java 1.1, the background color of offscreen images may
    be system dependent. Applications should use setColor followed by
    fillRect to ensure that an offscreen image is cleared to a specific color."

    --

    Knute Johnson
    email s/nospam/knute2009/

    --
    Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
    ------->>>>>>http://www.NewsDemon.com<<<<<<------
    Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
    Knute Johnson, May 19, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    623
    Kevin Spencer
    Jan 9, 2006
  2. dhaval dalal via JavaKB.com
    Replies:
    0
    Views:
    521
    dhaval dalal via JavaKB.com
    Feb 24, 2005
  3. Replies:
    9
    Views:
    664
    Michael Wojcik
    Aug 23, 2005
  4. defn noob
    Replies:
    1
    Views:
    373
    Mark Space
    Jun 28, 2008
Loading...

Share This Page