Results 1 to 2 of 2
  1. #1
    hyz_zsu is offline Member
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Question How to set the background of binary image?

    Hi All, I met a problem that can't set the background of the binary image which type is TYPE_BYTE_BINARY. It seem that the default color of image is black. I am try to set the background color as white. And I try to use the Graphics2D's setBackGround method, but it doesn't work. Can any body help?

    Java Code:
    // bi is a TYPE_BYTE_BINARY type BufferedImage
    BufferedImage rbi = new BufferedImage(w, h, bi.getType());
    Graphics2D g = rbi.createGraphics();	
    // The java api indicated that the setBackground method is for RGB color model	
    g.setBackground(Color.WHITE);
    // after rotation the magrin is filled by black color.
    g.rotate(Math.toRadians(angle), w / 2, h / 2);
    g.drawImage(bi, null, 0, 0);
    g.dispose();

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    With the Component setBackground method java will use the specified color to fill in the background when it renders the component. Setting the color for the graphics context (g) only sets the color. You must tell it what to draw/fill with the color.
    Java Code:
    g.setBackground(Color.WHITE);
    g.fillRect(0,0,w,h);

Similar Threads

  1. Background Image of Applet
    By BangJava in forum Java Applets
    Replies: 8
    Last Post: 11-24-2010, 06:48 AM
  2. Background image
    By leiferouis in forum New To Java
    Replies: 9
    Last Post: 03-08-2009, 06:49 PM
  3. Image as background
    By Java.child in forum AWT / Swing
    Replies: 2
    Last Post: 10-03-2008, 12:37 AM
  4. Center background image
    By Floetic in forum AWT / Swing
    Replies: 1
    Last Post: 04-24-2008, 06:50 PM
  5. Why this image background is black ?
    By samson in forum Java 2D
    Replies: 1
    Last Post: 07-17-2007, 05:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •