Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Drawing Buffered Images

Reply
Thread Tools

Drawing Buffered Images

 
 
Chase Preuninger
Guest
Posts: n/a
 
      05-19-2009
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?
 
Reply With Quote
 
 
 
 
Mark Space
Guest
Posts: n/a
 
      05-19-2009
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. "

 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      05-19-2009
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Guide to the standard library? Library for drawing in GUIs?drawing inbrowsers? defn noob Java 1 06-28-2008 02:50 AM
funny drawing software:ScreenPen,drawing directly on screen! yyzzbb@sina.com Digital Photography 0 02-04-2006 12:31 AM
System.Drawing For Drawing Text Images jjbutera@hotmail.com ASP .Net 1 01-09-2006 09:55 PM
whether is the standard input stream full buffered or line buffered after calling function setbuf()? kernelxu@hotmail.com C Programming 9 08-23-2005 02:24 PM
Convert a Buffered Image to ByteInputArray() for DICOM images dhaval dalal via JavaKB.com Java 0 02-24-2005 09:59 PM



Advertisments