Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

drawing BufferedImage

Status
Not open for further replies.

niritbakshi

Programmer
Oct 16, 2000
9
IL
How do i draw a BufferedImage?
The drawImage() method accept only Image objects.
 
BufferedImage extends Image so it is an Image object and drawImage() should accept it as an argument

Good luck
-pete
 
Ok, so i have another question.
How do I get BufferedImage?
Through the getImage() method?
 
Ok, here is a little example:

********** cut here: BufferedImgExample.html **********
<title></title>
<hr>
<applet code=BufferedImgExample.class width=200 height=200>
Your browser not support JAVA</applet>
<hr>
********** cut here ***********************************

********** cut here: BufferedImgExample.java **********
import java.applet.*;
import java.awt.*;

public class BufferedImgExample extends Applet {
static Image pic;

public void init() {
pic=createImage(200, 40);
Graphics g=pic.getGraphics();
g.setColor(Color.yellow);
g.fillRect(0, 0, 200, 40);
g.setColor(Color.red);
g.drawString(&quot;I'm a buffered image :).&quot;, 1, 20);
}

public void paint(Graphics g) {
g.drawImage(pic, 0, 0, this);
}
}
********** cut here ***********************************

Good luck.
Bye, Otto.
 
I don't want to nag you, but your example doesn't use
the BufferedImage class.
I wan't to use an object of this class in order to use
the setRGB() method of this class.
(I want to create fade effect).
Is there another way to create fade effect?
 
Sorry, I have changed the &quot;double buffer&quot; with &quot;BufferedImage&quot;. I have never use the BufferedImage class.
Sorry.

Otto
 
image = myKit.getImage(&quot;thefile.jpg&quot;);

MediaTracker tracker = new MediaTracker(this);
tracker.addImage(image, 0);

try
{
tracker.waitForID(0);
}

catch (InterruptedException e)
{}


// Set up the buffered Image.
imageInfo = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_BYTE_GRAY);


Graphics2D g2 = imageInfo.createGraphics();
// Draws image into imageinfo
g2.drawImage(image, 0, 0, null);


This is the code to make a buffered image from an image. Post back if you don't understand. You now made your buffered image and can draw it in paint() method using paint() method (overiding it).

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top